Instantly share code, notes, and snippets.

Embed
What would you like to do?
module FavouriteChangedBotTrigger
//#I @"D:\Projects\Bfexplorer\Development\Applications\BeloSoft.Bfexplorer.App\bin\Debug\"
#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>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| WaitForMarketTurnedAtInPlay
| ReportFavouriteChanged
/// <summary>
/// FavouriteChangedBotTrigger
/// </summary>
type FavouriteChangedBotTrigger(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable triggerStatus = TriggerStatus.WaitForMarketTurnedAtInPlay
let mutable favourite = nil<Selection>
let outputMessage message =
myBfexplorer.BfexplorerService.OutputMessage(message, market.Id)
let getFavourite() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.sortBy (fun mySelection -> mySelection.LastPriceTraded)
|> Seq.head
let reportFavourite (myFavourite : Selection) =
outputMessage (sprintf "%s: %.2f" myFavourite.Name myFavourite.LastPriceTraded)
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
match triggerStatus with
| TriggerStatus.WaitForMarketTurnedAtInPlay ->
if market.IsInPlay
then
favourite <- getFavourite()
reportFavourite favourite
triggerStatus <- TriggerStatus.ReportFavouriteChanged
TriggerResult.WaitingForOperation
| TriggerStatus.ReportFavouriteChanged ->
let currentFavourite = getFavourite()
if favourite.Id <> currentFavourite.Id
then
reportFavourite currentFavourite
TriggerResult.EndExecution
else
TriggerResult.WaitingForOperation
/// <summary>
/// EndExecution
/// </summary>
member _this.EndExecution() =
()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment