Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created June 22, 2020 10:42
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/28cef49abd8f09b91fe25bd0cf87fb7c to your computer and use it in GitHub Desktop.
Save StefanBelo/28cef49abd8f09b91fe25bd0cf87fb7c 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.Trading.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// toRaceDistance
/// </summary>
/// <param name="market"></param>
let toRaceDistance (market : Market) =
let marketInfo = market.MarketInfo
let raceDistanceString, inMiles =
let data = marketInfo.MarketName.Split(' ')
match marketInfo.BetEvent.CountryCode with
| "GB" | "IE" -> data.[0], true
| "US" -> data.[1], true
| "FR" -> data.[0], false
| _ -> data.[1], false
if inMiles
then
let distanceParts = raceDistanceString.Length / 2
let mutable distance = 0.0
let mutable index = 0
while index <= distanceParts do
distance <- distance + (
float ((int)raceDistanceString.[index] - (int)'0') *
match raceDistanceString.Chars(index + 1) with
| 'm' -> 1609.344
| _ -> 201.1708
)
index <- index + 2
distance
else
float (raceDistanceString.TrimEnd('m'))
/// <summary>
/// HorseRacingDistanceBotTrigger
/// </summary>
type HorseRacingDistanceBotTrigger(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let minRaceDistance = defaultArg (botTriggerParameters.GetParameter<int>("MinRaceDistance")) 1000
let maxRaceDistance = defaultArg (botTriggerParameters.GetParameter<int>("MaxRaceDistance")) 2000
let isHorseRacingMarket() =
market.MarketInfo.BetEventType.Id = 7
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
if isHorseRacingMarket()
then
let raceDistance = int (toRaceDistance market)
let numberOfRunners = market.Selections |> Seq.filter isActiveSelection |> Seq.length
outputMessage (sprintf "Race %s, distance: %d meters, number of runners: %d" market.MarketInfo.MarketName raceDistance numberOfRunners)
if raceDistance >= minRaceDistance && raceDistance <= maxRaceDistance
then
TriggerResult.ExecuteActionBot
else
TriggerResult.EndExecution
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!"
/// <summary>
/// EndExecution
/// </summary>
member _this.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment