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 MarketDataToSpreadsheet
#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"
#r "DevExpress.Data.v15.1.dll"
#r "DevExpress.Office.v15.1.Core.dll"
#r "DevExpress.Spreadsheet.v15.1.Core.dll"
open System.Collections.Generic
open DevExpress.XtraSpreadsheet
open BeloSoft.Data
open BeloSoft.Bfexplorer.Domain
open BeloSoft.Bfexplorer.Trading
let mutable lastRowIndex = -1
let marketRowIndexes = Dictionary<MarketId, int>()
let toMarketRowIndex (market : Market) =
lock marketRowIndexes (fun () ->
let marketId = market.Id
let status, rowIndex = marketRowIndexes.TryGetValue marketId
if status
then
rowIndex
else
lastRowIndex <- lastRowIndex + 1
marketRowIndexes.Add(marketId, lastRowIndex)
lastRowIndex
)
/// <summary>
/// MarketDataToSpreadsheet
/// </summary>
type MarketDataToSpreadsheet(market : Market, _selection : Selection, _botName : string, _botTriggerParameters : BotTriggerParameters, myBfexplorer : IMyBfexplorer) =
let mutable rowIndex = -1
let initialize (bfexplorerSpreadsheet : ISpreadsheetControl) =
lock bfexplorerSpreadsheet (fun () ->
let worksheet = bfexplorerSpreadsheet.Document.Worksheets.[0]
let marketInfo = market.MarketInfo
worksheet.[rowIndex, 0].SetValue(marketInfo.StartTime)
worksheet.[rowIndex, 1].SetValue(marketInfo.ToString())
worksheet.[rowIndex, 2].SetValue(market.TotalMatched)
)
let update (bfexplorerSpreadsheet : ISpreadsheetControl) =
lock bfexplorerSpreadsheet (fun () ->
let worksheet = bfexplorerSpreadsheet.Document.Worksheets.[0]
worksheet.[rowIndex, 2].SetValue(market.TotalMatched)
)
interface IBotTrigger with
/// <summary>
/// Execute
/// </summary>
member _this.Execute() =
let bfexplorerSpreadsheet = myBfexplorer.BfexplorerService.Bfexplorer.BfexplorerSpreadsheet
if isNullObj bfexplorerSpreadsheet
then
TriggerResult.EndExecutionWithMessage "Open the bfexplorer spreadsheet application!"
else
if rowIndex = -1
then
rowIndex <- toMarketRowIndex market
initialize bfexplorerSpreadsheet
else
update bfexplorerSpreadsheet
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.