Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
#r "BeloSoft.Data.dll"
#r "BeloSoft.Betfair.API.dll"
#r "BeloSoft.Bfexplorer.API.dll"
#r "BeloSoft.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Trading.dll"
#r "BeloSoft.Bfexplorer.Service.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
open System
open System.Net
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Service
ServicePointManager.Expect100Continue <- false
ServicePointManager.UseNagleAlgorithm <- false
ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12
let bfexplorerService = BfexplorerService()
let login (username, password) =
async {
let! result = bfexplorerService.Login(username, password)
return
match result with
| DataSuccessFailure.Success _ -> true
| DataSuccessFailure.Failure (_, _, errorMessage) -> printfn "Failed to login: %s" errorMessage; false
}
|> Async.RunSynchronously
let logout() =
bfexplorerService.Logout() |> Async.Ignore |> Async.RunSynchronously
let loadTodaysRaces() =
async {
let time = DateTime.Now
let filter = [
BetEventFilterParameter.BetEventTypeIds [| 7 |];
BetEventFilterParameter.Countries [| "GB"; "IE" |];
BetEventFilterParameter.MarketTypeCodes [| "WIN" |];
BetEventFilterParameter.StartTime (time, time.Date.AddHours(48.0))
]
let! result = bfexplorerService.GetMarketCatalogues(filter)
if result.IsSuccessResult
then
let marketIds =
result.SuccessResult
|> Seq.filter (fun market -> market.MarketInfo.StartTime.AddMinutes(-5.0) > time)
|> Seq.map (fun marketCatalog -> marketCatalog.MarketInfo.Id)
|> Seq.toArray
return! bfexplorerService.GetMarkets(marketIds)
else
return DataResult.Failure result.FailureMessage
}
|> Async.RunSynchronously
// Test
if login ("YourUserName", "YourPassword")
then
match loadTodaysRaces() with
| DataResult.Success markets ->
markets
|> List.sortBy (fun market -> market.MarketInfo.StartTime)
|> List.iter (fun market -> printfn "%A" market)
| DataResult.Failure errorMessage -> printfn "%s" errorMessage
logout()
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.