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\"
#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 System.IO
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
/// <summary>
/// MyTipsterSelection =
/// </summary>
type MyTipsterSelection =
{
Name : string
BotName : string
}
static member Create (name, botName) =
{
Name = name
BotName = botName
}
let mutable myTipsterSelections = list<MyTipsterSelection>.Empty
let loadMyTipsterSelections (filePathName : string) = async {
return
try
use reader = File.OpenText(filePathName)
while not reader.EndOfStream do
let data = reader.ReadLine().Split(';')
if data.Length = 2
then
myTipsterSelections <- myTipsterSelections @ [ MyTipsterSelection.Create(data.[0], data.[1]) ]
Result.Success
with
| ex -> Result.Failure ex.Message
}
let getMyTipsterSelection name =
myTipsterSelections |> List.tryFind (fun myTipsterSelection -> myTipsterSelection.Name = name)
/// <summary>
/// MySelectionActionBot
/// </summary>
type MySelectionActionBot =
{
Selection : Selection
BotName : string
}
static member Create (selection, botName) =
{
Selection = selection
BotName = botName
}
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| WaitToLoadMyTipsterSelections
| SetMySelections
| ExecuteActionBot
| ReportError of string
/// <summary>
/// HorseRacingCsvSelectionBotTrigger
/// </summary>
type HorseRacingCsvSelectionBotTrigger(market : Market, _selection : Selection, _botName : string, botTriggerParameters : BotTriggerParameters, _myBfexplorer : IMyBfexplorer) =
let mutable triggerStatus = TriggerStatus.Initialize
let mutable mySelectionActionBotsToExecute = nil<Queue<MySelectionActionBot>>
let isHorseRacingMarket() =
market.MarketInfo.BetEventType.Id = 7 && market.MarketDescription.MarketType = "WIN"
let setErrorStatus errorMessage =
triggerStatus <- TriggerStatus.ReportError errorMessage
let initialize() =
lock myTipsterSelections (fun () ->
if myTipsterSelections.IsEmpty
then
triggerStatus <- TriggerStatus.WaitToLoadMyTipsterSelections
Async.StartWithContinuations(
computation = loadMyTipsterSelections (defaultArg (botTriggerParameters.GetParameter<string>("CsvFile")) String.Empty),
continuation = (fun result ->
if result.IsSuccessResult
then
triggerStatus <- TriggerStatus.SetMySelections
else
setErrorStatus result.FailureMessage
),
exceptionContinuation = (fun ex -> setErrorStatus ex.Message),
cancellationContinuation = (fun ex -> setErrorStatus ex.Message)
)
else
triggerStatus <- TriggerStatus.SetMySelections
)
let setMySelections() =
let mySelectionActionBots =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.choose (fun mySelection ->
match getMyTipsterSelection mySelection.Name with
| Some myTipsterSelection -> Some (MySelectionActionBot.Create(mySelection, myTipsterSelection.BotName))
| None -> None
)
|> Seq.toList
if mySelectionActionBots.IsEmpty
then
false
else
mySelectionActionBotsToExecute <- Queue<MySelectionActionBot>(mySelectionActionBots)
true
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member __.Execute() =
match triggerStatus with
| TriggerStatus.Initialize ->
if isHorseRacingMarket()
then
initialize()
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecutionWithMessage "You can execute this bot only on a horse racing market!"
| TriggerStatus.WaitToLoadMyTipsterSelections -> TriggerResult.WaitingForOperation
| TriggerStatus.SetMySelections ->
if setMySelections()
then
triggerStatus <- TriggerStatus.ExecuteActionBot
TriggerResult.WaitingForOperation
else
TriggerResult.EndExecution
| TriggerStatus.ExecuteActionBot ->
let mySelectionActionBot = mySelectionActionBotsToExecute.Dequeue()
TriggerResult.ExecuteMyActionBotOnMarketSelectionAndContinueToExecute (mySelectionActionBot.BotName, market, mySelectionActionBot.Selection, list.Empty, mySelectionActionBotsToExecute.Count > 0)
| TriggerStatus.ReportError errorMessage -> TriggerResult.EndExecutionWithMessage errorMessage
/// <summary>
/// EndExecution
/// </summary>
member __.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.