Skip to content

Instantly share code, notes, and snippets.

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/ebdf8257e0d29dc8bda3bae1437a6641 to your computer and use it in GitHub Desktop.
Save StefanBelo/ebdf8257e0d29dc8bda3bae1437a6641 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.Data
open BeloSoft.Betfair
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// SelectionData
/// </summary>
type SelectionData(selection : Selection) =
member __.Selection
with get() = selection
member val ActualSP : float = 0.0 with get, set
static member DataKey = "SelectionData"
static member Set (selection : Selection) =
selection.SetData(SelectionData.DataKey, SelectionData(selection))
static member Get (selection : Selection) =
selection.GetData<SelectionData>(SelectionData.DataKey)
let updateSelectionSpPrice (selection : Selection, runner : API.Models.Runner) =
SelectionData.Get selection
|> Option.iter (fun selectionData -> selectionData.ActualSP <- runner.sp.actualSP)
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitForInPlay
| WaitForUpdateSpPrices
| TriggerMyActionBot
| ReportError of string
/// <summary>
/// HorseRacingSpFavouriteSimpleBotTrigger
/// </summary>
type HorseRacingSpFavouriteSimpleBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let isHorseRacingMarket() =
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN"
let createBetfairSpPrices() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.iter SelectionData.Set
let updateBetfairSpPrices() =
async {
let! result = myBfexplorer.BfexplorerService.UpdateMarketData(market, API.Models.PriceProjection.DefaultBetfairSpPrice(), updateSelectionSpPrice)
status <-
if result.IsSuccessResult
then
TriggerStatus.TriggerMyActionBot
else
TriggerStatus.ReportError result.FailureMessage
}
|> Async.Start
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let getMySelection() = maybe {
let selectionDatas =
market.Selections
|> Seq.choose SelectionData.Get
|> Seq.sortBy (fun selectionData -> selectionData.ActualSP)
|> Seq.toList
// Report betfair SP prices
selectionDatas
|> List.map (fun selectionData -> sprintf "%s: %.2f" selectionData.Selection.Name selectionData.ActualSP)
|> String.concat "\n"
|> outputMessage
// Get the favourite
let favourite = selectionDatas.[0].Selection
let secondFavourite = selectionDatas.[1].Selection
// Not joined favourites
if favourite.LastPriceTraded <> secondFavourite.LastPriceTraded
then
return favourite
}
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match status with
| TriggerStatus.Initialize ->
if isHorseRacingMarket()
then
status <- TriggerStatus.WaitForInPlay
createBetfairSpPrices()
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!"
| TriggerStatus.WaitForInPlay ->
if market.IsInPlay
then
status <- TriggerStatus.WaitForUpdateSpPrices
updateBetfairSpPrices()
TriggerResult.WaitingForOperation
| TriggerStatus.WaitForUpdateSpPrices -> TriggerResult.WaitingForOperation
| TriggerStatus.TriggerMyActionBot ->
match getMySelection() with
| Some mySelection -> TriggerResult.ExecuteActionBotOnSelection mySelection
| None -> TriggerResult.EndExecution
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment