Instantly share code, notes, and snippets.

Embed
What would you like to do?
FootballWaveStrategyBotTrigger
// 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.Models
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| OpenCorrectScoreMarket
| BackNilNilDraw
| WaitToUpdateMatchScore
| UpdateMatchScore
| BackGoal
| ExecuteCloseMyBetPositionBot
| ReportError of string
| EndExecution
/// <summary>
/// FootballWaveStrategyBotTrigger
/// </summary>
type FootballWaveStrategyBotTrigger(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let timeToBackCorrectScore = TimeSpan.FromMinutes(defaultArg (botTriggerParameters.GetParameter<float>("TimeToBackCorrectScore")) 0.0)
let matchTimeToStop = defaultArg (botTriggerParameters.GetParameter<int>("MatchTimeToStop")) 85
let botNameBackNilNilDraw = defaultArg (botTriggerParameters.GetParameter<string>("BotNameBackNilNilDraw")) "Back 0 - 0"
let botNameBackGoal = defaultArg (botTriggerParameters.GetParameter<string>("BotNameBackGoal")) "Back Goal"
let botNameCloseMyBetPosition = defaultArg (botTriggerParameters.GetParameter<string>("BotNameCloseMyBetPosition")) "Close My Football Bet Position"
let mutable status = TriggerStatus.Initialize
let mutable correctScoreMarket = nil<Market>
let mutable footballMatch = nil<FootballMatch>
let mutable footballMatchResourceLocker = nil<ResourceLocker>
let mutable score = "0 - 0"
let mutable backedSelection = nil<Selection>
let mutable closeMyBetPositionBotExecuted = false
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let isFootballMatch() =
market.MarketInfo.BetEventType.Id = 1 && market.MarketDescription.MarketType = "MATCH_ODDS"
let canStartMyStrategy() =
//not market.IsInPlay
true
let correctScoreMarketOpened (result : DataResult<Market list>) =
status <-
if result.IsSuccessResult
then
correctScoreMarket <- result.SuccessResult.Head
TriggerStatus.BackNilNilDraw
else
TriggerStatus.ReportError result.FailureMessage
let canUpdateMatchData() =
market.IsInPlay && not footballMatchResourceLocker.IsLocked
let footballMatchScoreUpdated (result : bool) =
status <-
if result
then
if footballMatch.IsUpdated
then
outputMessage (footballMatch.ToString())
if footballMatch.MatchTime >= matchTimeToStop
then
TriggerStatus.EndExecution
else
let currentScore = footballMatch.Score
if score <> currentScore
then
score <- currentScore
TriggerStatus.BackGoal
else
TriggerStatus.WaitToUpdateMatchScore
else
TriggerStatus.ReportError "Failed to update the match score!"
let getGoalScoredSelection() = maybe {
let mySelection =
let index =
let scoreDifference = footballMatch.ScoreDifference
if scoreDifference < 0y
then
1
elif scoreDifference > 0y
then
0
else
2
market.Selections.[index]
if (isNullObj backedSelection) || (backedSelection.Id <> mySelection.Id)
then
return mySelection
}
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
match status with
| TriggerStatus.Initialize ->
if isFootballMatch()
then
if canStartMyStrategy()
then
status <- TriggerStatus.OpenCorrectScoreMarket
footballMatch <- CreateFootballMatch market
footballMatchResourceLocker <- market |> CreateFootballMatchResourceLocker 20.0
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecution
else
TriggerResult.EndExecutionWithMessage "You can execute this bot only on a football market."
| TriggerStatus.OpenCorrectScoreMarket ->
TriggerResult.OpenAssociatedMarkets ([| "CORRECT_SCORE" |], correctScoreMarketOpened)
| TriggerStatus.BackNilNilDraw ->
if isMarketStartTime timeToBackCorrectScore market
then
status <- TriggerStatus.WaitToUpdateMatchScore
TriggerResult.ExecuteMyActionBotOnMarketSelectionAndContinueToExecute (botNameBackNilNilDraw, correctScoreMarket, correctScoreMarket.Selections.[0], list.Empty, true)
else
TriggerResult.WaitingForOperation
| TriggerStatus.WaitToUpdateMatchScore ->
if canUpdateMatchData()
then
status <- TriggerStatus.UpdateMatchScore
TriggerResult.WaitingForOperation
| TriggerStatus.UpdateMatchScore ->
footballMatchResourceLocker.Lock()
TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated)
| TriggerStatus.BackGoal ->
status <-
if closeMyBetPositionBotExecuted
then
TriggerStatus.WaitToUpdateMatchScore
else
TriggerStatus.ExecuteCloseMyBetPositionBot
match getGoalScoredSelection() with
| Some mySelection ->
backedSelection <- mySelection
TriggerResult.ExecuteMyActionBotOnMarketSelectionAndContinueToExecute (botNameBackGoal, market, mySelection, list.Empty, true)
| None -> TriggerResult.WaitingForOperation
| TriggerStatus.ExecuteCloseMyBetPositionBot ->
status <- TriggerStatus.WaitToUpdateMatchScore
closeMyBetPositionBotExecuted <- true
TriggerResult.ExecuteMyActionBotOnMarketSelectionAndContinueToExecute (botNameCloseMyBetPosition, market, market.Selections.[0], list.Empty, true)
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
| TriggerStatus.EndExecution -> TriggerResult.EndExecution
/// <summary>
/// EndExecution
/// </summary>
member _this.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment