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\"
#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"
#r "BeloSoft.Bfexplorer.Service.Core.dll"
*)
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| PlaceBet
| WaitForResult
/// <summary>
/// PlaceBetAtEmptyPrice
/// </summary>
type PlaceBetAtEmptyPrice(_market : Market, selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) =
let mutable status = TriggerStatus.Initialize
let mutable betsPlaced = false
let getEmptyPrice (betType : BetType) =
let priceGridData = selection.PriceGridData.DataContext
let startIndex, nextIndex, findFun =
if betType = BetType.Back
then
priceGridData.BestToLayIndex, -1, (fun (priceData : PriceData) -> priceData.ToLay = 0.0)
else
priceGridData.BestToBackIndex, +1, (fun (priceData : PriceData) -> priceData.ToBack = 0.0)
let mutable doLoop = true
let mutable index = startIndex
let mutable price = 0.0
while doLoop do
if index > 0 && index < OddsData.NumberOfOdds
then
let priceData = priceGridData.GetPriceData(index)
if findFun priceData
then
price <- priceData.Price
doLoop <- false
else
index <- index + nextIndex
else
doLoop <- false
if price = 0.0
then
None
else
Some price
let onBetsPlaced (_status : bool) =
betsPlaced <- true
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match status with
| TriggerStatus.Initialize ->
status <- TriggerStatus.PlaceBet
selection.PriceGridDataEnabled <- true
TriggerResult.WaitingForOperation
| TriggerStatus.PlaceBet ->
let betType = defaultArg (botTriggerParameters.GetEnumParameter<BetType>("BetType")) BetType.Back
match getEmptyPrice betType with
| Some price ->
status <- TriggerStatus.WaitForResult
let stake = defaultArg (botTriggerParameters.GetParameter<float>("Stake")) 2.0
let bets = [ SelectionBetOrder.Create(selection, betType, price, 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