Skip to content

Instantly share code, notes, and snippets.

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/48d9561530d804aee7f05773f3ce0d73 to your computer and use it in GitHub Desktop.
Save StefanBelo/48d9561530d804aee7f05773f3ce0d73 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"
open System
open System.IO
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Service
(* Uncomment when developing the script in Visual Studio *)
//let bfexplorer : IBfexplorerConsole = nil
let getTodaysRaces() = async {
let! resultOpenMyFavouriteBetEvent = bfexplorer.OpenMyFavouriteBetEvent("Horse Racing")
if resultOpenMyFavouriteBetEvent.IsSuccessResult
then
let today = DateTime.Today
let marketInfos =
bfexplorer.BetEventBrowserMarketCatalogs
|> List.filter (fun marketCatalog -> marketCatalog.MarketInfo.StartTime.Date = today)
|> List.map (fun marketCatalog -> marketCatalog.MarketInfo)
if marketInfos.Length = 0
then
return DataResult.Failure "No horse racing today!"
else
return! bfexplorer.GetMyMarkets(marketInfos)
else
return DataResult.Failure "No 'Horse Racing' favourite bet event defined!"
}
let loadMyJockeysOrTrainers() =
let loadFromFile fileName =
try
File.ReadLines(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), sprintf "%s.txt" fileName))
|> Seq.filter (String.IsNullOrEmpty >> not)
|> Seq.toList
with
| _ -> list.Empty
let myJockeys = loadFromFile "MyJockeys"
let myTrainers = loadFromFile "MyTrainers"
match myJockeys.IsEmpty, myTrainers.IsEmpty with
| true, true -> DataResult.Failure "No jockeys and trainers defined!"
| _ -> DataResult.Success (myJockeys, myTrainers)
async {
match loadMyJockeysOrTrainers() with
| DataResult.Success (myJockeys, myTrainers) ->
let! result = getTodaysRaces()
if result.IsSuccessResult
then
let isMySelection (selection : Selection) =
match selection.MetaData with
| Some metaData -> myJockeys |> List.contains metaData.JockeyName || myTrainers |> List.contains metaData.TrainerName
| None -> false
let myMarketSelectionsData =
result.SuccessResult
|> List.choose (fun market ->
let mySelections =
market.Selections
|> Seq.filter (fun selection -> isActiveSelection selection && isMySelection selection)
|> Seq.toList
if mySelections.IsEmpty
then
None
else
Some (market, mySelections)
)
if myMarketSelectionsData.IsEmpty
then
printfn "No selections today!"
else
bfexplorer.OpenMyMarkets(myMarketSelectionsData |> List.map fst)
let myMarketSelections =
myMarketSelectionsData
|> List.map (fun (market, selections) ->
selections
|> List.map (fun selection ->
{
MarketSelection.Market = market
MarketSelection.Selection = selection
}
)
)
|> List.concat
bfexplorer.WatchMarketSelections(myMarketSelections)
else
printfn "%s" result.FailureMessage
| DataResult.Failure errorMessage -> printfn "%s" errorMessage
}
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment