Last active
February 3, 2019 19:23
-
-
Save StefanBelo/78594a7891420182e1c527e62ff7e32c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 BeloSoft.Data | |
open BeloSoft.Bfexplorer.Domain | |
open BeloSoft.Bfexplorer.Trading | |
open BeloSoft.Bfexplorer.FootballScoreProvider.Models | |
/// <summary> | |
/// TriggerStatus | |
/// </summary> | |
type TriggerStatus = | |
| Initialize | |
| WaitToUpdateMatchScore | |
| UpdateMatchScore | |
| OpenOverUnderMarket | |
| ExecuteMyStrategy | |
| EndMyStrategy | |
| ReportError of string | |
/// <summary> | |
/// FootballGoalsDifferenceOverUnderBotTrigger | |
/// </summary> | |
type FootballGoalsDifferenceOverUnderBotTrigger(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) = | |
let executeAtMatchTime = defaultArg (botTriggerParameters.GetParameter<int>("ExecuteAtMatchTime")) 80 | |
let allowedGoalDifference = sbyte (defaultArg (botTriggerParameters.GetParameter<int>("AllowedGoalDifference")) 2) | |
let mutable status = TriggerStatus.Initialize | |
let mutable footballMatch = nil<FootballMatch> | |
let mutable footballMatchResourceLocker = nil<ResourceLocker> | |
let mutable executeOnMarket = nil<Market> | |
let outputMessage message = | |
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id) | |
let canUpdateMatchData() = | |
market.IsInPlay && not footballMatchResourceLocker.IsLocked | |
let isTimeToExecuteMyStrategy() = | |
footballMatch.MatchTime >= executeAtMatchTime | |
let canExecuteMyStrategy() = | |
(abs footballMatch.ScoreDifference) >= allowedGoalDifference | |
let footballMatchScoreUpdated (result : bool) = | |
if result | |
then | |
status <- TriggerStatus.WaitToUpdateMatchScore | |
if footballMatch.IsUpdated && isTimeToExecuteMyStrategy() | |
then | |
outputMessage (footballMatch.ToString()) | |
status <- | |
if canExecuteMyStrategy() | |
then | |
TriggerStatus.OpenOverUnderMarket | |
else | |
TriggerStatus.EndMyStrategy | |
else | |
status <- TriggerStatus.ReportError "Failed to update the match score!" | |
let initialize() = | |
if market.MarketInfo.BetEventType.Id = 1 && market.MarketDescription.MarketType = "MATCH_ODDS" | |
then | |
footballMatch <- CreateFootballMatch market | |
footballMatchResourceLocker <- market |> CreateFootballMatchResourceLocker 20.0 | |
TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated) | |
else | |
TriggerResult.EndExecutionWithMessage "You can execute this bot only on a football market." | |
let openOverUnderMarket() = | |
let marketName = sprintf "OVER_UNDER_%d5" (footballMatch.HomeScore + footballMatch.AwayScore) | |
OpenAssociatedMarkets ([| marketName |], fun result -> | |
status <- | |
if result.IsSuccessResult | |
then | |
executeOnMarket <- result.SuccessResult.[0] | |
TriggerStatus.ExecuteMyStrategy | |
else | |
TriggerStatus.ReportError (sprintf "Failed to open the market: %s" marketName) | |
) | |
interface IBotTrigger with | |
/// <summary> | |
/// Execute | |
/// </summary> | |
member _this.Execute() = | |
match status with | |
| TriggerStatus.Initialize -> initialize() | |
| TriggerStatus.WaitToUpdateMatchScore -> | |
if canUpdateMatchData() | |
then | |
status <- TriggerStatus.UpdateMatchScore | |
TriggerResult.WaitingForOperation | |
| TriggerStatus.UpdateMatchScore -> | |
footballMatchResourceLocker.Lock() | |
TriggerResult.UpdateFootballMatchScore (footballMatch, footballMatchScoreUpdated) | |
| TriggerStatus.OpenOverUnderMarket -> openOverUnderMarket() | |
| TriggerStatus.ExecuteMyStrategy -> | |
TriggerResult.ExecuteActionBotOnMarketSelectionAndContinueToExecute (executeOnMarket, executeOnMarket.Selections.[0], false) | |
| TriggerStatus.EndMyStrategy -> TriggerResult.EndExecution | |
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage | |
/// <summary> | |
/// EndExecution | |
/// </summary> | |
member _this.EndExecution() = | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment