Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Last active October 7, 2019 08:32
Show Gist options
  • Save StefanBelo/7729476b32ffeb7e33db368781035fa3 to your computer and use it in GitHub Desktop.
Save StefanBelo/7729476b32ffeb7e33db368781035fa3 to your computer and use it in GitHub Desktop.
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