Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created September 6, 2018 16:08
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/0e9cc74b951958e8cf9be3d64f50d672 to your computer and use it in GitHub Desktop.
Save StefanBelo/0e9cc74b951958e8cf9be3d64f50d672 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"
open System
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
open BeloSoft.Bfexplorer.FootballScoreProvider
open BeloSoft.Bfexplorer.FootballScoreProvider.API.Models
open BeloSoft.Bfexplorer.FootballScoreProvider.Models
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitToUpdateMatchScore
| UpdateMatchScore
| FailedToUpdateMatchScore
| WaitToGetMatchDetails
| ExecuteActionBot
/// <summary>
/// FootballSecondHalfKickOffBotTrigger
/// </summary>
type FootballSecondHalfKickOffBotTrigger(market : Market, selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let mutable footballMatch = nil<FootballMatch>
let mutable matchDetailData = nil<MatchDetailData>
let mutable timeToExecute = DateTime.MaxValue
let setTimeToExecute() =
timeToExecute <- DateTime.Now.AddSeconds(30.0)
let isSecondHalfKickedOff (updateDetails : UpdateDetailData[]) =
if updateDetails.Length > 0
then
updateDetails |> Array.exists (fun updateDetail -> updateDetail.UpdateType = "SecondHalfKickOff")
else
false
let footballMatchScoreUpdated (result : bool) =
status <-
if result
then
Async.StartWithContinuations(
computation = FootballScoreProvider.GetMatchDetails(footballMatch),
continuation = (fun result ->
status <-
if result.IsSuccessResult
then
matchDetailData <- result.SuccessResult
setTimeToExecute()
if isSecondHalfKickedOff matchDetailData.UpdateDetails
then
TriggerStatus.ExecuteActionBot
else
TriggerStatus.WaitToUpdateMatchScore
else
TriggerStatus.FailedToUpdateMatchScore
),
exceptionContinuation = (fun _ -> status <- TriggerStatus.FailedToUpdateMatchScore),
cancellationContinuation = (fun _ -> status <- TriggerStatus.FailedToUpdateMatchScore)
)
TriggerStatus.WaitToGetMatchDetails
else
TriggerStatus.FailedToUpdateMatchScore
let initialize() =
if market.MarketInfo.BetEventType.Id = 1 && market.MarketDescription.MarketType = "MATCH_ODDS"
then
footballMatch <- CreateFootballMatch market
TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated)
else
TriggerResult.EndExecutionWithMessage "You can execute this bot only on a football market."
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match status with
| TriggerStatus.Initialize -> initialize()
| TriggerStatus.WaitToUpdateMatchScore ->
if DateTime.Now >= timeToExecute
then
status <- TriggerStatus.UpdateMatchScore
TriggerResult.WaitingForOperation
| TriggerStatus.UpdateMatchScore -> TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated)
| TriggerStatus.FailedToUpdateMatchScore -> TriggerResult.EndExecutionWithMessage "Failed to update the match score."
| TriggerStatus.WaitToGetMatchDetails -> TriggerResult.WaitingForOperation
| TriggerStatus.ExecuteActionBot -> TriggerResult.ExecuteActionBotOnSelection selection
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment