Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module BfexplorerBot
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
#r "BeloSoft.Data.dll"
#r "BeloSoft.Betfair.API.dll"
#r "BeloSoft.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Trading.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
open BeloSoft.Betfair.API
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
[<Literal>]
let MySelectionDataKey = "MySelectionData"
/// <summary>
/// MySelectionData
/// </summary>
type MySelectionData =
{
OfferedOnCheckPrice : float
MaxOfferedOnPrice : float
MaxOfferedAmount : float
}
static member Set (selection : Selection, runner : Models.Runner, checkPrice : float) =
let offeredAmount =
match runner.ex.availableToBack |> Seq.tryFind (fun priceSize -> priceSize.price = checkPrice) with
| Some priceSize -> priceSize.size
| None -> 0.0
let maxOfferedPriceSize =
runner.ex.availableToBack
|> Seq.filter (fun priceSize -> priceSize.price >= 1.1)
|> Seq.maxBy (fun priceSize -> priceSize.size)
let data =
{
MySelectionData.OfferedOnCheckPrice = offeredAmount
MySelectionData.MaxOfferedOnPrice = maxOfferedPriceSize.price
MySelectionData.MaxOfferedAmount = maxOfferedPriceSize.size
}
selection.SetData(MySelectionDataKey, data)
static member Get (selection : Selection) =
selection.GetData<MySelectionData>(MySelectionDataKey)
/// <summary>
/// getPriceProjection
/// </summary>
let getPriceProjection() =
let priceProjection = Models.PriceProjection.DefaultActiveMarket()
priceProjection.priceData <- [| Models.PriceData.EX_ALL_OFFERS; Models.PriceData.EX_TRADED |]
priceProjection
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| LoadFullMarketData
| WaitForFullMarketDataBeingLoaded
| ReportResult
| ReportError of string
/// <summary>
/// LoadFullMarketDataBot
/// </summary>
type LoadFullMarketDataBot(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let checkPrice = defaultArg (botTriggerParameters.GetParameter<float>("CheckPrice")) 2.00
let mutable triggerStatus = TriggerStatus.LoadFullMarketData
let updateSelectionData (mySelection : Selection, runner : Models.Runner) =
MySelectionData.Set(mySelection, runner, checkPrice)
let loadFullMarketData() =
Async.StartWithContinuations(
computation = myBfexplorer.BfexplorerService.UpdateMarketData(market, getPriceProjection(), updateSelectionData),
continuation = (fun result ->
triggerStatus <-
if result.IsSuccessResult
then
TriggerStatus.ReportResult
else
TriggerStatus.ReportError result.FailureMessage
),
exceptionContinuation = (fun ex -> triggerStatus <- TriggerStatus.ReportError ex.Message),
cancellationContinuation = (fun ex -> triggerStatus <- TriggerStatus.ReportError ex.Message)
)
let myDataToString() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun mySelection -> mySelection.LastPriceTraded)
|> Seq.map (fun mySelection ->
match MySelectionData.Get mySelection with
| Some mySelectionData -> sprintf "%.2f | %.2f @ %.2f" mySelectionData.OfferedOnCheckPrice mySelectionData.MaxOfferedAmount mySelectionData.MaxOfferedOnPrice
| None -> "no data!"
|> sprintf "%s: %s" mySelection.Name
)
|> String.concat "\n"
|> sprintf "\nOffered amount on: %.2f\n%s" checkPrice
interface IBotTrigger with
member __.Execute() =
match triggerStatus with
| TriggerStatus.LoadFullMarketData ->
loadFullMarketData()
triggerStatus <- TriggerStatus.WaitForFullMarketDataBeingLoaded
TriggerResult.WaitingForOperation
| TriggerStatus.ReportResult -> TriggerResult.EndExecutionWithMessage (myDataToString())
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
| _ -> TriggerResult.WaitingForOperation
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.