// 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 BeloSoft.Data | |
open BeloSoft.Bfexplorer.Domain | |
open BeloSoft.Bfexplorer.Trading | |
/// <summary> | |
/// SelectionData | |
/// </summary> | |
type SelectionData(selection : Selection, forecastPrice : float) = | |
let getForecastPriceDifference() = | |
(toPriceProbability forecastPrice) - (toPriceProbability selection.LastPriceTraded) | |
let mutable factor = getForecastPriceDifference() | |
member __.Selection | |
with get() = selection | |
member __.ForecastPrice | |
with get() = forecastPrice | |
member __.Factor | |
with get() = factor | |
member __.CalculateFactor() = | |
factor <- getForecastPriceDifference() | |
/// <summary> | |
/// TriggerStatus | |
/// </summary> | |
type TriggerStatus = | |
| Initialize | |
| TriggerMyActionBot | |
/// <summary> | |
/// HorseRacingForecastPriceBotTrigger | |
/// </summary> | |
type HorseRacingForecastPriceBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) = | |
let mutable selectionDatas = nil<SelectionData list> | |
let mutable status = TriggerStatus.Initialize | |
let isHorseRacingMarket() = | |
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN" | |
let createCelectionDatas() = | |
selectionDatas <- | |
market.Selections | |
|> Seq.filter isActiveSelection | |
|> Seq.choose (fun selection -> | |
match selection.MetaData with | |
| Some metaData -> Some (SelectionData(selection, metaData.ForecastPrice)) | |
| None -> None | |
) | |
|> Seq.toList | |
let recalculateFactorValues() = | |
selectionDatas |> List.iter (fun selectionData -> selectionData.CalculateFactor()) | |
let outputMessage message = | |
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id) | |
let reportData (selectionDatas : SelectionData list) = | |
selectionDatas | |
|> List.map (fun selectionData -> | |
let selection = selectionData.Selection | |
sprintf "%s: %.2f - %.2f | %.3f" selection.Name selection.LastPriceTraded selectionData.ForecastPrice selectionData.Factor | |
) | |
|> String.concat "\n" | |
|> outputMessage | |
let getMySelection() = maybe { | |
let mySelectionDatas = selectionDatas |> List.sortByDescending (fun selectionData -> selectionData.Factor) | |
reportData mySelectionDatas | |
return mySelectionDatas.Head.Selection | |
} | |
interface IBotTrigger with | |
/// <summary> | |
/// Execute | |
/// </summary> | |
member __.Execute() = | |
match status with | |
| TriggerStatus.Initialize -> | |
if isHorseRacingMarket() | |
then | |
status <- TriggerStatus.TriggerMyActionBot | |
createCelectionDatas() | |
TriggerResult.WaitingForOperation | |
else | |
TriggerResult.EndExecutionWithMessage "You can run this bot on a horse racing market only!" | |
| TriggerStatus.TriggerMyActionBot -> | |
recalculateFactorValues() | |
match getMySelection() with | |
| Some mySelection -> TriggerResult.ExecuteActionBotOnSelection mySelection | |
| None -> 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