Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created September 7, 2018 18:48
Show Gist options
  • Select an option

  • Save StefanBelo/dbcc7bfedc6873935e75e38d63fa45ed to your computer and use it in GitHub Desktop.

Select an option

Save StefanBelo/dbcc7bfedc6873935e75e38d63fa45ed to your computer and use it in GitHub Desktop.
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.Data
open BeloSoft.Betfair
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// BetfairSpPrices
/// </summary>
type BetfairSpPrices() =
member val NearPrice : float = 0.0 with get, set
member val FarPrice : float = 0.0 with get, set
member val ActualSP : float = 0.0 with get, set
static member DataKey = "bsp"
static member Set (selection : Selection) =
selection.SetData(BetfairSpPrices.DataKey, BetfairSpPrices())
static member Get (selection : Selection) =
selection.GetData<BetfairSpPrices>(BetfairSpPrices.DataKey)
/// <summary>
/// updateSelectionSpPrices
/// </summary>
/// <param name="selection"></param>
/// <param name="runner"></param>
let updateSelectionSpPrices (selection : Selection, runner : API.Models.Runner) =
BetfairSpPrices.Get selection
|> Option.iter (fun betfairSpPrices ->
let spPrices = runner.sp
betfairSpPrices.NearPrice <- spPrices.nearPrice
betfairSpPrices.FarPrice <- spPrices.farPrice
betfairSpPrices.ActualSP <- spPrices.actualSP
)
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitForInPlay
| WaitForUpdateSpPrices
| ReportResults
| ReportError of string
/// <summary>
/// HorseRacingSpBotTrigger
/// </summary>
type HorseRacingSpBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let showHorsesData() =
let selectionDataToString (selection : Selection) = maybe {
let! metaData = selection.MetaData
let! betfairSpPrices = BetfairSpPrices.Get selection
return sprintf "%s: %.2f | %.2f | %.2f" selection.Name selection.LastPriceTraded metaData.ForecastPrice betfairSpPrices.ActualSP
}
market.Selections
|> Seq.filter isNotRemovedSelection
|> Seq.choose selectionDataToString
|> String.concat "\n"
|> outputMessage
interface IBotTrigger with
member __.Execute() =
match status with
| TriggerStatus.Initialize ->
if market.MarketInfo.BetEventType.Id = 7
then
status <- TriggerStatus.WaitForInPlay
market.Selections |> Seq.iter BetfairSpPrices.Set
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!"
| TriggerStatus.WaitForInPlay ->
if market.IsInPlay
then
status <- TriggerStatus.WaitForUpdateSpPrices
async {
let! result = myBfexplorer.BfexplorerService.UpdateMarketData(market, API.Models.PriceProjection.DefaultBetfairSpPrice(), updateSelectionSpPrices)
status <-
if result.IsSuccessResult
then
TriggerStatus.ReportResults
else
TriggerStatus.ReportError result.FailureMessage
}
|> Async.Start
TriggerResult.WaitingForOperation
| TriggerStatus.WaitForUpdateSpPrices -> TriggerResult.WaitingForOperation
| TriggerStatus.ReportResults ->
showHorsesData()
TriggerResult.EndExecution
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment