Created
June 4, 2020 11:46
-
-
Save StefanBelo/a2edfcc93b948011f09c58995a2e69be 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 BeloSoft.Data | |
open BeloSoft.Bfexplorer.Domain | |
open BeloSoft.Bfexplorer.Trading | |
/// <summary> | |
/// SelectionData | |
/// </summary> | |
type SelectionData(selection : Selection) = | |
let totalMatchedHistory = HistoryValue(selection.TotalMatched) | |
member _this.RecalculatePoolPrice(time : DateTime, marketTotalMatched : float) = | |
if totalMatchedHistory.SetValue(selection.TotalMatched) | |
then | |
let totalMatched = totalMatchedHistory.Value - totalMatchedHistory.PreviousValue | |
selection.PriceTradedHistory.MyValues.AddUniqueValue(time, toProbabilityPrice ((totalMatched / marketTotalMatched) * 100.0)) | |
/// <summary> | |
/// TriggerStatus | |
/// </summary> | |
type TriggerStatus = | |
| Initialize | |
| UpdateData | |
/// <summary> | |
/// PoolPriceToSparklineChart | |
/// </summary> | |
type PoolPriceToSparklineChart(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) = | |
let updateInterval = TimeSpan.FromSeconds(defaultArg (botTriggerParameters.GetParameter<float>("UpdateInterval")) 5.0) | |
let hideChartsWhenClosed = defaultArg (botTriggerParameters.GetParameter<bool>("HideChartsWhenClosed")) false | |
let mutable triggerStatus = TriggerStatus.Initialize | |
let mutable timeToUpdate = DateTime.MinValue | |
let totalMatchedHistory = HistoryValue(market.TotalMatched) | |
let mutable selectionDatas = nil<SelectionData list> | |
let enableMyValues enabled = | |
market.Selections | |
|> Seq.iter (fun selectionData -> selectionData.PriceTradedHistory.MyValuesEnabled <- enabled) | |
let doUpdate (time, totalMatched) = | |
selectionDatas | |
|> List.iter (fun selectionData -> selectionData.RecalculatePoolPrice(time, totalMatched)) | |
let initialize() = | |
selectionDatas <- | |
market.Selections | |
|> Seq.filter isActiveSelection | |
|> Seq.map SelectionData | |
|> Seq.toList | |
doUpdate (DateTime.Now, totalMatchedHistory.Value) | |
enableMyValues true | |
let update time = | |
if totalMatchedHistory.SetValue(market.TotalMatched) | |
then | |
doUpdate (time, totalMatchedHistory.Value - totalMatchedHistory.PreviousValue) | |
interface IBotTrigger with | |
/// <summary> | |
/// Execute | |
/// </summary> | |
member _this.Execute() = | |
match triggerStatus with | |
| TriggerStatus.Initialize -> | |
initialize() | |
triggerStatus <- TriggerStatus.UpdateData | |
| TriggerStatus.UpdateData -> | |
let time = DateTime.Now | |
if time >= timeToUpdate | |
then | |
update time | |
timeToUpdate <- time.Add(updateInterval) | |
TriggerResult.WaitingForOperation | |
/// <summary> | |
/// EndExecution | |
/// </summary> | |
member _this.EndExecution() = | |
if hideChartsWhenClosed | |
then | |
enableMyValues false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment