Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Last active January 29, 2022 17:24
Show Gist options
  • Select an option

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

Select an option

Save StefanBelo/5a87fa8a4ace5427afb40aaee4c1c2d4 to your computer and use it in GitHub Desktop.
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
#r "BeloSoft.Data.dll"
#r "BeloSoft.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
#r "BeloSoft.Bfexplorer.TimeformProviderPro.dll"
open System
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Service
open BeloSoft.Bfexplorer.TimeformProviderPro
open BeloSoft.Bfexplorer.TimeformProviderPro.Models
let bfexplorer = nil<IBfexplorerConsole>
let reportError message =
printfn "Error: %s" message
let getMyHorseRacingMarkets() = async {
match! bfexplorer.OpenMyFavouriteBetEvent("Horse Racing") with
| Result.Success ->
let marketInfos = bfexplorer.BetEventBrowserMarketCatalogues |> List.map (fun marketCatalogue -> marketCatalogue.MarketInfo)
return! bfexplorer.GetMyMarkets(marketInfos)
| Result.Failure errorMessage -> return DataResult.Failure errorMessage
}
let isMyselection (metaData : SelectionMetaData, horseRunnerData : HorseRunnerData) =
let data = horseRunnerData.Data
metaData.ForecastPrice <= 20.0 && data.RatingStars <= 3uy && not data.HorseInForm && not data.JockeyWonOnHorse
let toMyHorseRunnerData (horsesData : HorseRunnerData list) (selection : Selection) = maybe {
let! horseRunnerData =
let name = selection.Name
horsesData |> List.tryFind (fun horseRunnerData -> String.Compare(horseRunnerData.Name, name, true) = 0)
let! metaData = selection.MetaData
if isMyselection (metaData, horseRunnerData)
then
return (selection, horseRunnerData, horsesData)
}
async {
match! getMyHorseRacingMarkets() with
| DataResult.Success markets ->
let timeformProvider = TimeformProvider()
match! timeformProvider.GetAllHorsesData() with
| DataResult.Success horsesData ->
let myMarketSelections = ResizeArray<MarketSelection>()
for market in markets do
market.Selections
|> Seq.filter isActiveSelection
|> Seq.choose (toMyHorseRunnerData horsesData)
|> Seq.iter (fun (selection, horseRunnerData, horsesData) ->
printfn "%s | %d" selection.Name horseRunnerData.Data.RatingStars
market.SetData("Horses Data", horsesData)
myMarketSelections.Add(MarketSelection.Create(market, selection))
)
if myMarketSelections.Count > 0
then
let! result =
bfexplorer.StartMyBotStrategy(
"Lay trade 3 ticks", TimeSpan.FromMinutes(-1.0), 1.0 (* 1 second *),
myMarketSelections,
checkMyResults = true,
cloneMarket = false
)
if result.IsSuccessResult
then
printfn "Started my strategy on %d selection/s." myMarketSelections.Count
else
reportError result.FailureMessage
else
printfn "No selections!"
| DataResult.Failure errorMessage -> reportError errorMessage
| DataResult.Failure errorMessage -> reportError errorMessage
}
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment