Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created October 21, 2019 12:39
Show Gist options
  • Save StefanBelo/ab0fe9df4277c147149b0b9cfb627519 to your computer and use it in GitHub Desktop.
Save StefanBelo/ab0fe9df4277c147149b0b9cfb627519 to your computer and use it in GitHub Desktop.
// Bfexplorer cannot be held responsible for any losses or damages incurred during the use of this betfair bot.
// It is up to you to determine the level of risk you wish to trade under.
// Do not gamble with money you cannot afford to lose.
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.FootballScoreProvider.dll"
#r "BeloSoft.Bfexplorer.Trading.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
#r "DevExpress.Data.v15.1.dll"
#r "DevExpress.Office.v15.1.Core.dll"
#r "DevExpress.Spreadsheet.v15.1.Core.dll"
//*)
open System
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
let toMarketNames (value : string) =
if String.IsNullOrEmpty value
then
Array.empty
else
value.Split(',')
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| DoOpenMarkets
| WaitToOpenMarkets
| WatchFavourites
| ReportError of string
/// <summary>
/// OpenAssociatedMarkets
/// </summary>
type OpenAssociatedMarkets(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.DoOpenMarkets
let mutable markets = nil<Market list>
let onOpenAssociatedMarkets (result : DataResult<Market list>) =
status <-
if result.IsSuccessResult
then
markets <- market :: result.SuccessResult
TriggerStatus.WatchFavourites
else
TriggerStatus.ReportError result.FailureMessage
let doWatchFavourites() =
markets |> List.iter (fun myMarket -> myBfexplorer.BfexplorerService.Bfexplorer.WatchMarketSelections(myMarket, [ (getFavourites myMarket).Head ]))
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
match status with
| TriggerStatus.DoOpenMarkets ->
let marketNames = toMarketNames (defaultArg (botTriggerParameters.GetParameter<string>("Markets")) String.Empty)
if marketNames.Length = 0
then
TriggerResult.EndExecution
else
status <- TriggerStatus.WaitToOpenMarkets
TriggerResult.OpenAssociatedMarkets (marketNames, onOpenAssociatedMarkets)
| TriggerStatus.WaitToOpenMarkets -> TriggerResult.WaitingForOperation
| TriggerStatus.WatchFavourites ->
if defaultArg (botTriggerParameters.GetParameter<bool>("WatchFavourites")) false
then
doWatchFavourites()
TriggerResult.EndExecution
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
/// <summary>
/// EndExecution
/// </summary>
member _this.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment