SmartQuant Discussion

Quickly retrieve latest historical price
Page 1 of 1

Author:  abasqd [ Fri Apr 12, 2019 5:52 am ]
Post subject:  Quickly retrieve latest historical price

I'm making an implementation of CurrencyConverter which uses the latest saved historical bid/ask. I'm getting the latest historical bid/ask like so:

using System;
using SmartQuant;
using System.Diagnostics;
namespace OpenQuant
class Program
static void Main(string[] args)
Framework framework = Framework.Current;
Stopwatch stopwatch = new Stopwatch();

Instrument instrument = framework.InstrumentManager.Get("EURUSD");
TickSeries bidSeries = framework.DataManager.GetHistoricalBids(instrument);
Bid bid = (Bid)bidSeries[bidSeries.Count-1];
Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
Bid 04/03/2019 15:37:00.000 4 193 1.12342 0
Time elapsed: 00:00:01.8565314

The problem I have is that the whole TickSeries is being collected and this takes ~ 2 seconds, but I'm only using the last tick in this series. Is there a way to access the last tick without getting the full TickSeries so that this operation is faster?

I know of DataManager.GetBid/Ask but these seem to only work if the instrument has been subscribed, but I don't want to subscribe due to realtime streaming limitations, I'm just after historical which I will periodically update.


Author:  skuvv [ Fri Apr 12, 2019 10:32 am ]
Post subject:  Re: Quickly retrieve latest historical price

DataSeries series = framework.DataManager.GetDataSeries(instrument, DataObjectType.Trade);
if (series != null && series.Count > 0)
    Trade trade = (Trade)series[series.Count - 1];

will be much faster in your case

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group