Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 System
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitForPreviousResult
| WaitForRaceStart
| WaitForStartTradingSession
/// <summary>
/// HorseRacingBotTrigger
/// </summary>
type HorseRacingBotTrigger(market : Market, _selection : Selection, botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let myStrategyResults = myBfexplorer.BfexplorerService |> MyStrategyOperations.RegisterMyStrategy botName
let timeToStart = defaultArg (botTriggerParameters.GetParameter<float>("TimeToStart")) 40.0
let mutable status = TriggerStatus.Initialize
let mutable startTime = DateTime.MinValue
let isHorseRacingMarket() =
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN"
let initialize() =
if isHorseRacingMarket()
then
status <- TriggerStatus.WaitForPreviousResult
// Add your initialization here!
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!"
let waitForPreviousResult() =
let waitingForOperation =
if market.IsInPlay
then
false
else
if myStrategyResults.CanExecuteMyStrategy
then
status <- TriggerStatus.WaitForRaceStart
match myStrategyResults.BettingStreak with
| BettingStreak.LosingStreak numberOfLosses -> numberOfLosses <= 3
| _ -> true
else
true
if waitingForOperation
then
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecution
let setStartData() =
// Add your start data initialization here!
status <- TriggerStatus.WaitForStartTradingSession
startTime <- DateTime.Now
let isTimeToStart() =
(DateTime.Now - startTime).TotalSeconds >= timeToStart
let getMySelection() : Selection option =
// Add your algorithm to choose your selection here!
None
interface IBotTrigger with
member __.Execute() =
match status with
| TriggerStatus.Initialize -> initialize()
| TriggerStatus.WaitForPreviousResult -> waitForPreviousResult()
| TriggerStatus.WaitForRaceStart ->
if market.IsInPlay
then
setStartData()
TriggerResult.WaitingForOperation
| TriggerStatus.WaitForStartTradingSession ->
if isTimeToStart()
then
match getMySelection() with
| Some mySelection ->
myStrategyResults.AddMarket(market)
TriggerResult.ExecuteActionBotOnSelection mySelection
| None -> TriggerResult.EndExecution
else
TriggerResult.WaitingForOperation
member __.EndExecution() =
()
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.