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 InPlayTradedVolumeToSpreadsheet
#I @"C:\Program Files (x86)\BeloSoft\Bfexplorer\"
//#I @"D:\Projects\Bfexplorer\Development\Applications\BeloSoft.Bfexplorer.App\bin\Debug\"
#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"
#r "DevExpress.Data.v15.1.dll"
#r "DevExpress.Office.v15.1.Core.dll"
#r "DevExpress.Spreadsheet.v15.1.Core.dll"
open System
open DevExpress.Spreadsheet
open DevExpress.XtraSpreadsheet
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
[<Literal>]
let ZeroTotalMatchedDataKey = "zeroTotalMatched"
let getZeroTotalMatched (selection : Selection) =
selection.Data.[ZeroTotalMatchedDataKey] :?> float
/// <summary>
/// TriggerStatus
/// </summary>
type TriggerStatus =
| Initialize
| UpdateData
/// <summary>
/// InPlayTradedVolumeToSpreadsheet
/// </summary>
type InPlayTradedVolumeToSpreadsheet(market : Market, selection : Selection, botName : string, botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let updateInterval = TimeSpan.FromSeconds(defaultArg (botTriggerParameters.GetParameter<float>("UpdateInterval")) 1.0)
let mutable timeToUpdate = DateTime.MinValue
let mutable isInPlay = false
let mutable bfexplorerSpreadsheet = nil<ISpreadsheetControl>
let mutable worksheet = nil<Worksheet>
let mutable triggerStatus = TriggerStatus.Initialize
let initialize() =
let worksheetName = market.Id
let workbook = bfexplorerSpreadsheet.Document
worksheet <-
if workbook.Worksheets.Contains(worksheetName)
then
workbook.Worksheets.[worksheetName]
else
workbook.Worksheets.Add(worksheetName)
try
bfexplorerSpreadsheet.BeginUpdate()
worksheet.[0, 0].SetValue(market.MarketFullName)
worksheet.[1, 1].SetValue("Price")
worksheet.[1, 2].SetValue("Total Matched")
worksheet.[1, 3].SetValue("In-Play Matched")
let mutable row = 2
market.Selections
|> Seq.filter isActiveSelection
|> Seq.iter (fun mySelection ->
worksheet.[row, 0].SetValue(mySelection.Name)
worksheet.[row, 1].SetValue(mySelection.LastPriceTraded)
worksheet.[row, 2].SetValue(mySelection.TotalMatched)
row <- row + 1
)
finally
bfexplorerSpreadsheet.EndUpdate()
let setZeroTotalMatched() =
market.Selections
|> Seq.filter isActiveSelection
|> Seq.iter (fun mySelection -> mySelection.SetData(ZeroTotalMatchedDataKey, mySelection.TotalMatched))
let update() =
try
bfexplorerSpreadsheet.BeginUpdate()
let mutable row = 2
market.Selections
|> Seq.filter isActiveSelection
|> Seq.iter (fun mySelection ->
worksheet.[row, 1].SetValue(mySelection.LastPriceTraded)
worksheet.[row, 2].SetValue(mySelection.TotalMatched)
if isInPlay
then
worksheet.[row, 3].SetValue(mySelection.TotalMatched - (getZeroTotalMatched mySelection))
row <- row + 1
)
finally
bfexplorerSpreadsheet.EndUpdate()
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member this.Execute() =
match triggerStatus with
| TriggerStatus.Initialize ->
bfexplorerSpreadsheet <- myBfexplorer.BfexplorerService.Bfexplorer.BfexplorerSpreadsheet
if isNullObj bfexplorerSpreadsheet
then
TriggerResult.EndExecutionWithMessage "Open bfexplorer spreadsheet application!"
else
initialize()
triggerStatus <- TriggerStatus.UpdateData
TriggerResult.WaitingForOperation
| TriggerStatus.UpdateData ->
if not isInPlay
then
isInPlay <- market.IsInPlay
if isInPlay
then
setZeroTotalMatched()
if DateTime.Now >= timeToUpdate
then
update()
timeToUpdate <- DateTime.Now.Add(updateInterval)
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
You can’t perform that action at this time.