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"
#r "BeloSoft.Bfexplorer.TennisScoreProvider.dll"
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
open BeloSoft.Bfexplorer.TennisScoreProvider.Models
let BreakPoints = [ "0 - 40"; "15 - 40"; "30 - 40"; "40 - Av" ]
type TriggerStatus =
| Initialize
| WaitForBreakPoint
| BreakPointAlert
type TennisBreakPointAlertBot(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 setGameId = 0.0
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let isTennisMatch() =
market.MarketInfo.BetEventType.Id = 2 && market.MarketDescription.MarketType = "MATCH_ODDS"
let isBreakPoint() =
let player1, player2 =
if tennisMatch.FirstPlayer.IsServing
then
tennisMatch.FirstPlayer, tennisMatch.SecondPlayer
else
tennisMatch.SecondPlayer, tennisMatch.FirstPlayer
let points = sprintf "%s - %s" player1.PointsWon player2.PointsWon
BreakPoints |> List.contains points
let isNewSetGame() =
let player1, player2 = tennisMatch.FirstPlayer, tennisMatch.SecondPlayer
let newSetGameId = float (player1.SetsWon + player2.SetsWon) + (float (player1.GamesWon + player2.GamesWon) * 0.01)
let status = setGameId <> newSetGameId
if status
then
setGameId <- newSetGameId
status
let getReceiverPlayerName() =
let player =
if tennisMatch.FirstPlayer.IsServing
then
tennisMatch.SecondPlayer
else
tennisMatch.FirstPlayer
player.Name
let matchScoreUpdated (isUpdated : bool) =
if isUpdated
then
market.MyDescription <- sprintf "%s, %s, %s" tennisMatch.Sets tennisMatch.Games tennisMatch.Points
if isBreakPoint() && isNewSetGame()
then
triggerStatus <- TriggerStatus.BreakPointAlert
outputMessage (sprintf "%s | %s: %s" (tennisMatch.ToString()) (getReceiverPlayerName()) tennisMatch.Points)
interface IBotTrigger with
member __.Execute() =
match triggerStatus with
| TriggerStatus.Initialize ->
if isTennisMatch()
then
triggerStatus <- TriggerStatus.WaitForBreakPoint
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.WaitForBreakPoint ->
if not tennisMatchResourceLocker.IsLocked
then
tennisMatchResourceLocker.Lock()
TriggerResult.UpdateTennisMatchScore (tennisMatch, matchScoreUpdated)
else
TriggerResult.WaitingForOperation
| TriggerStatus.BreakPointAlert ->
triggerStatus <- TriggerStatus.WaitForBreakPoint
TriggerResult.AlertMessage (sprintf "Break point %s" (getReceiverPlayerName()))
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.