Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created August 12, 2018 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanBelo/b661c5f0d8e99911c32feb72002996c7 to your computer and use it in GitHub Desktop.
Save StefanBelo/b661c5f0d8e99911c32feb72002996c7 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.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
let getSelectionsSortedByLastPriceTraded (market : Market) =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun selection -> selection.LastPriceTraded)
|> Seq.toList
let getFavouritiesBookValue numberOfFavourites (favourities : Selection list) =
favourities
|> List.take (min numberOfFavourites favourities.Length)
|> List.sumBy (fun selection -> toPriceProbability selection.LastPriceTraded)
let initializeMyData (market : Market) =
let selections = getSelectionsSortedByLastPriceTraded market
selections, selections |> getFavouritiesBookValue 3, selections.Length
let getWinner (market : Market) =
market.Selections |> Seq.tryFind isWinnerSelection
type TriggerStatus =
| ReportFavourites
| WaitForMarketBeingClosed
type MyBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable triggerStatus = TriggerStatus.ReportFavourites
let selections, favouritesBookValue, numberOfRunners = initializeMyData market
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let reportFavourites() =
selections
|> List.map (fun selection -> sprintf "%s: %.2f" selection.Name selection.LastPriceTraded)
|> String.concat ", "
|> outputMessage
let myDataToString() =
sprintf "%s, %.2f, %d" selections.Head.Name favouritesBookValue numberOfRunners
let winnerDataToString (winner : Selection) =
let winnerId = winner.Id
let winnerFavouriteIndex = (selections |> List.findIndex (fun selection -> selection.Id = winnerId)) + 1
sprintf "%s (%d)" winner.Name winnerFavouriteIndex
let reportMyData() =
let logMessage =
match getWinner market with
| Some winner -> sprintf "%s, %s" (myDataToString()) (winnerDataToString winner)
| None -> myDataToString()
outputMessage logMessage
interface IBotTrigger with
member __.Execute() =
match triggerStatus with
| TriggerStatus.ReportFavourites ->
triggerStatus <- TriggerStatus.WaitForMarketBeingClosed
reportFavourites()
| _ -> ()
TriggerResult.WaitingForOperation
member __.EndExecution() =
reportMyData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment