Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| EvaluateMarketData of Market
| ReportError of string
/// <summary>
/// HorseRacingWinToBePlacedBotTrigger
/// </summary>
type HorseRacingWinToBePlacedBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let isMyMarket() =
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN"
let outputMessage (message : string) =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let getMarketSelectionById id (myMarket : Market) =
myMarket.Selections |> Seq.find (fun mySelection -> mySelection.Id = id)
let toSelectionsString (winSelection : Selection, toBePlacedSelection : Selection) =
sprintf "%s: %.2f | %.2f ~ %.2f" winSelection.Name winSelection.LastPriceTraded
winSelection.TotalMatched toBePlacedSelection.TotalMatched
let reportData (toBePlacedMarket : Market) =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun mySelection -> mySelection.LastPriceTraded)
|> Seq.map (fun mySelection -> toSelectionsString (mySelection, toBePlacedMarket |> getMarketSelectionById mySelection.Id))
|> String.concat "\n"
|> outputMessage
let getMySelection (toBePlacedMarket : Market) =
let favourites =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun mySelection -> mySelection.LastPriceTraded)
|> Seq.toList
//let myFavourites = favourites |> List.take (min 5 favourites.Length)
let mySelectionId =
toBePlacedMarket.Selections
|> Seq.filter isActiveSelection
|> Seq.sortByDescending (fun mySelection -> mySelection.TotalMatched)
|> Seq.head
|> fun mySelection -> mySelection.Id
//myFavourites |> List.tryFind (fun mySelection -> mySelection.Id = mySelectionId)
favourites |> List.tryFind (fun mySelection -> mySelection.Id = mySelectionId)
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
match status with
| Initialize ->
if isMyMarket()
then
TriggerResult.OpenAssociatedMarkets ([| "PLACE" |], fun result ->
status <-
if result.IsSuccessResult
then
TriggerStatus.EvaluateMarketData result.SuccessResult.Head
else
TriggerStatus.ReportError "Failed to open the 'To Be Placed' market!"
)
else
TriggerResult.EndExecutionWithMessage "You can execute this bot only on a horse racing win market."
| EvaluateMarketData toBePlacedMarket ->
reportData toBePlacedMarket
match getMySelection toBePlacedMarket with
| Some mySelection -> TriggerResult.ExecuteActionBotOnSelection mySelection
| None -> TriggerResult.EndExecution
| ReportError message -> TriggerResult.EndExecutionWithMessage message
/// <summary>
/// EndExecution
/// </summary>
member _this.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment