Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created March 27, 2019 20:14
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/7faa78da4113b678b53adb9ee601f0fa to your computer and use it in GitHub Desktop.
Save StefanBelo/7faa78da4113b678b53adb9ee601f0fa 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"
#r "BeloSoft.Bfexplorer.TennisScoreProvider.dll"
open System
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
open BeloSoft.Bfexplorer.TennisScoreProvider.Models
type TriggerStatus =
| Initialize
| WaitForGameScore
| GameScoreAlert
type TennisGameScoreAlertBot(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable triggerStatus = TriggerStatus.Initialize
let mutable tennisMatch = nil<TennisMatch>
let mutable tennisMatchResourceLocker = nil<ResourceLocker>
let mutable gameScore = String.Empty
let mutable scoreId = String.Empty
let getScoreId() =
sprintf "%d %s" (tennisMatch.FirstPlayer.SetsWon + tennisMatch.SecondPlayer.SetsWon) gameScore
let setScoreId() =
scoreId <- sprintf "%d %s" (tennisMatch.FirstPlayer.SetsWon + tennisMatch.SecondPlayer.SetsWon) gameScore
let gameScores =
match botTriggerParameters.GetParameter<string>("GameScores") with
| Some gameScoresText -> gameScoresText.Split('|') |> List.ofArray
| None -> [ "5 - 4"; "6 - 5" ]
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let isTennisMatch() =
market.MarketInfo.BetEventType.Id = 2 && market.MarketDescription.MarketType = "MATCH_ODDS"
let isGameScore() =
let player1, player2 =
if tennisMatch.FirstPlayer.IsServing
then
tennisMatch.FirstPlayer, tennisMatch.SecondPlayer
else
tennisMatch.SecondPlayer, tennisMatch.FirstPlayer
gameScore <- sprintf "%d - %d" player1.GamesWon player2.GamesWon
if gameScores |> List.contains gameScore
then
scoreId <> getScoreId()
else
false
let matchScoreUpdated (isUpdated : bool) =
if isUpdated
then
market.MyDescription <- sprintf "%s, %s, %s" tennisMatch.Sets tennisMatch.Games tennisMatch.Points
if isGameScore()
then
triggerStatus <- TriggerStatus.GameScoreAlert
outputMessage (tennisMatch.ToString())
interface IBotTrigger with
member __.Execute() =
match triggerStatus with
| TriggerStatus.Initialize ->
if isTennisMatch()
then
triggerStatus <- TriggerStatus.WaitForGameScore
tennisMatch <- market |> CreateTennisMatch
tennisMatchResourceLocker <- market |> CreateTennisMatchResourceLocker 10.0
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a tennis match market only!"
| TriggerStatus.WaitForGameScore ->
if not tennisMatchResourceLocker.IsLocked
then
tennisMatchResourceLocker.Lock()
TriggerResult.UpdateTennisMatchScore (tennisMatch, matchScoreUpdated)
else
TriggerResult.WaitingForOperation
| TriggerStatus.GameScoreAlert ->
triggerStatus <- TriggerStatus.WaitForGameScore
setScoreId()
TriggerResult.AlertMessage (sprintf "Game score %s" gameScore)
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment