Skip to content

Instantly share code, notes, and snippets.

@StefanBelo
Created September 13, 2018 10:03
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/32e7ab71e022a7c46d2a8798d2497c10 to your computer and use it in GitHub Desktop.
Save StefanBelo/32e7ab71e022a7c46d2a8798d2497c10 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.Bfexplorer.Domain.dll"
#r "BeloSoft.Bfexplorer.Trading.dll"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| PlaceBets
| WaitForResult
/// <summary>
/// PlaceBetsInTradedRangeBot
/// </summary>
type PlaceBetsInTradedRangeBot(_market : Market, selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let mutable betsPlaced = false
let getTradedRange minimalTradedVolume =
let tradedPriceDatas =
selection.PriceGridData.Data
|> Array.filter (fun priceData -> priceData.TotalMatched >= minimalTradedVolume)
|> Array.map (fun priceData -> priceData.Price)
if tradedPriceDatas.Length > 1
then
let maximalPriceTraded = tradedPriceDatas |> Array.head
let minimalPriceTraded = tradedPriceDatas |> Array.last
Some (minimalPriceTraded, maximalPriceTraded)
else
None
let onBetsPlaced (_status : bool) =
betsPlaced <- true
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match status with
| TriggerStatus.Initialize ->
status <- TriggerStatus.PlaceBets
selection.PriceGridDataEnabled <- true
TriggerResult.WaitingForOperation
| TriggerStatus.PlaceBets ->
let minimalTradedVolume = defaultArg (botTriggerParameters.GetParameter<float>("MinimalTradedVolume")) 5.0
match getTradedRange minimalTradedVolume with
| Some (minimalPriceTraded, maximalPriceTraded) ->
status <- TriggerStatus.WaitForResult
let stake = defaultArg (botTriggerParameters.GetParameter<float>("Stake")) 2.0
let bets = [
SelectionBetOrder.Create(selection, BetType.Back, maximalPriceTraded, stake)
SelectionBetOrder.Create(selection, BetType.Lay, minimalPriceTraded, stake)
]
TriggerResult.PlaceBets (bets, PersistenceType.Lapse, onBetsPlaced)
| None -> TriggerResult.EndExecution
| TriggerStatus.WaitForResult ->
if betsPlaced
then
TriggerResult.EndExecution
else
TriggerResult.WaitingForOperation
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment