Created
July 13, 2020 15:25
-
-
Save StefanBelo/d3f710831ee2f98ee553add1cf387036 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 System.Collections.Generic | |
open BeloSoft.Data | |
open BeloSoft.Bfexplorer.Domain | |
open BeloSoft.Bfexplorer.Trading | |
/// <summary> | |
/// PriceImprovementValue | |
/// </summary> | |
type PriceImprovementValue = | |
{ | |
Time : float | |
Value : sbyte | |
} | |
static member Create (time, value) = | |
{ | |
Time = time | |
Value = value | |
} | |
/// <summary> | |
/// TriggerStatus | |
/// </summary> | |
type TriggerStatus = | |
| ExecuteActionBot | |
| ReferenceActionBot | |
| CheckActionBotStatus | |
/// <summary> | |
/// PlaceBetPriceImprovementInTimeBot | |
/// </summary> | |
type PlaceBetPriceImprovementInTimeBot(market : Market, selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) as this = | |
let toPriceImprovementValues() = | |
let dataValues = defaultArg (botTriggerParameters.GetParameter("PriceImprovementValues")) "10~1" | |
Queue ( | |
try | |
let values = dataValues.Split('~') |> Array.map int | |
let counts = values.Length / 2 | |
let mutable index = 0 | |
seq { | |
while index < counts do | |
yield PriceImprovementValue.Create (float (values.[index]), sbyte (values.[index + 1])) | |
index <- index + 2 | |
} | |
with | |
| _ -> Seq.empty | |
) | |
let priceImprovementValues = toPriceImprovementValues() | |
let getNextPriceImprovementValues() = | |
if priceImprovementValues.Count = 0 | |
then | |
DateTime.MaxValue, 0y | |
else | |
let priceImprovementValue = priceImprovementValues.Dequeue() | |
DateTime.Now.AddSeconds(priceImprovementValue.Time), priceImprovementValue.Value | |
let mutable status = TriggerStatus.ExecuteActionBot | |
let mutable actionBot = nil<Bot> | |
let mutable actionBotParameters = nil<PlaceBetBotParameters> | |
let mutable timeToChangePriceImprovement, priceImprovement = getNextPriceImprovementValues() | |
let getActionBotValues() = | |
let isMyActionBot (bot : Bot) = | |
bot :? PlaceBetBot | |
let selectionId = selection.Id | |
market.RunningBots | |
|> Seq.tryFind (fun bot -> | |
if isMyActionBot bot && isNotNullObj bot.RunningOnSelection | |
then | |
bot.RunningOnSelection.Id = selectionId | |
else | |
false | |
) | |
|> Option.map (fun bot -> bot, (bot :?> PlaceBetBot).Parameters) | |
let isActionBotRunning() = | |
actionBot.Status <> BotStatus.ExecutionEnded | |
let isTimeToChangePriceImprovement() = | |
DateTime.Now >= timeToChangePriceImprovement | |
let setNextPriceImprovementValues() = | |
actionBotParameters.PriceImprovement <- priceImprovement | |
let newTimeToChangePriceImprovement, newPriceImprovement = getNextPriceImprovementValues() | |
timeToChangePriceImprovement <- newTimeToChangePriceImprovement | |
priceImprovement <- newPriceImprovement | |
interface IBotTrigger with | |
/// <summary> | |
/// Execute | |
/// </summary> | |
member __.Execute() = | |
match status with | |
| TriggerStatus.ExecuteActionBot -> | |
status <- TriggerStatus.ReferenceActionBot | |
TriggerResult.ExecuteActionBotOnMarketSelectionAndContinueToExecute (market, selection, true) | |
| TriggerStatus.ReferenceActionBot -> | |
status <- TriggerStatus.CheckActionBotStatus | |
match getActionBotValues() with | |
| Some (bot, botParameters) -> | |
actionBot <- bot | |
actionBotParameters <- botParameters | |
TriggerResult.WaitingForOperation | |
| None -> TriggerResult.EndExecutionWithMessage "No action bot is running!" | |
| TriggerStatus.CheckActionBotStatus -> | |
if isActionBotRunning() | |
then | |
if isTimeToChangePriceImprovement() | |
then | |
setNextPriceImprovementValues() | |
TriggerResult.WaitingForOperation | |
else | |
TriggerResult.EndExecution | |
/// <summary> | |
/// EndExecution | |
/// </summary> | |
member __.EndExecution() = | |
() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment