Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created May 25, 2018 11:43
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/2f0240e4a640f6d33353be0382e75ecf to your computer and use it in GitHub Desktop.
Save StefanBelo/2f0240e4a640f6d33353be0382e75ecf 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 HorseRacingBetOnLongestInRange
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
//#I @"D:\Projects\Bfexplorer\Development\Applications\BeloSoft.Bfexplorer.App\bin\Debug\"
#r "BeloSoft.Data.dll"
#r "BeloSoft.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Trading.dll"
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| ExecuteMyBot
/// <summary>
/// HorseRacingBetOnLongestInRange
/// </summary>
type HorseRacingBetOnLongestInRange(market : Market, selection : Selection, botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let initialize() =
if market.MarketInfo.BetEventType.Id = 7
then
status <- TriggerStatus.ExecuteMyBot
WaitingForOperation
else
EndExecutionWithMessage "You can run this bot on a horse racing market only!"
let getSelectionsSortedByPrice() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun mySelection -> mySelection.LastPriceTraded)
|> Seq.toList
let isClearFavourite (selections : Selection list) =
let favourite = selections.[0]
let secondFavourite = selections.[1]
let favouriteProbabilityDifference = defaultArg (botTriggerParameters.GetParameter<float>("FavouriteProbabilityDifference")) 10.0
let probabilityDifference = (toPriceProbability favourite.LastPriceTraded) - (toPriceProbability secondFavourite.LastPriceTraded)
probabilityDifference >= favouriteProbabilityDifference
let isAllowedOddsRange (minimumPrice : float, maximumPrice : float) (mySelection : Selection) =
let price = mySelection.LastPriceTraded
price >= minimumPrice && price <= maximumPrice
let getMySelection (selections : Selection list) =
let minimalOdds = defaultArg (botTriggerParameters.GetParameter<float>("MinimalOdds")) 10.0
let maximalOdds = defaultArg (botTriggerParameters.GetParameter<float>("MaximalOdds")) 20.0
let minimalNumberOfSelections = defaultArg (botTriggerParameters.GetParameter<int>("MinimalNumberOfSelections")) 3
let mySelections =
selections
|> List.skip 1
|> List.filter (isAllowedOddsRange (minimalOdds, maximalOdds))
if mySelections.Length >= minimalNumberOfSelections
then
Some (mySelections |> List.last)
else
None
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member this.Execute() =
match status with
| TriggerStatus.Initialize -> initialize()
| TriggerStatus.ExecuteMyBot ->
let selections = getSelectionsSortedByPrice()
if isClearFavourite selections
then
match getMySelection selections with
| Some mySelection -> ExecuteActionBotOnSelection mySelection
| None -> EndExecution
else
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