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/73b307378df829123026bec9d7c8b234 to your computer and use it in GitHub Desktop.
Save StefanBelo/73b307378df829123026bec9d7c8b234 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 System
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// SelectionData
/// </summary>
type SelectionData(selection : Selection) as this =
let highLowValue = HighLowValue(selection.LastPriceTraded)
do
selection.PriceGridDataEnabled <- true
this.SetHighLowValues()
member __.Selection
with get() = selection
member __.PreOffLow
with get() = highLowValue.LowValue
member __.PreOffHigh
with get() = highLowValue.HighValue
member __.InPlayLow
with get() = selection.PriceTradedHistory.MinimalPriceTraded
member __.InPlayHigh
with get() = selection.PriceTradedHistory.MaximalPriceTraded
member __.SetHighLowValues() =
selection.PriceGridData.Data
|> Array.iter (fun priceData ->
if priceData.TotalMatched > 0.0
then
highLowValue.Set(priceData.Price)
)
selection.PriceTradedHistory.ResetMinimalMaximalPrice()
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitForInPlay
| InPlayAction
/// <summary>
/// HorseRacingHighLowTradedBotTrigger
/// </summary>
type HorseRacingHighLowTradedBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let mutable selectionDatas = nil<SelectionData list>
let isHorseRacingMarket() =
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN"
let getSelectionDatas() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.map SelectionData
|> Seq.toList
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let reportData() =
selectionDatas
|> List.map (fun selectionData ->
let selection = selectionData.Selection
let isWinner = isWinnerSelection selection
sprintf "%s: %.2f ~ %.2f | %.2f %s" selection.Name
selectionData.PreOffLow selectionData.PreOffHigh
(if isWinner then selectionData.InPlayHigh else selectionData.InPlayLow)
(if isWinner then "- isWinner" else String.Empty)
)
|> String.concat "\n"
|> outputMessage
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match status with
| TriggerStatus.Initialize ->
if isHorseRacingMarket()
then
status <- TriggerStatus.WaitForInPlay
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!"
| TriggerStatus.WaitForInPlay ->
if market.IsInPlay
then
status <- TriggerStatus.InPlayAction
selectionDatas <- getSelectionDatas()
TriggerResult.WaitingForOperation
| TriggerStatus.InPlayAction -> TriggerResult.WaitingForOperation
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
if market.MarketStatus = MarketStatus.Closed
then
reportData()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment