public virtual Task <TimeSerie <ITradeBar> > GetHistoryNavigator(DateTime historyStartTime) { //todo fetch history from database TimeSerie <ITradeBar> newNavigator = new TimeSerie <ITradeBar>(); //consolidate the currently available data using (var navigator = new TimeSerieNavigator <ITradeBar>(this.DataSource.Ticks)) { //add all records up to current time navigator.SeekNearestBefore(historyStartTime); while (navigator.MoveNext() && navigator.Time <= this.DataSource.Ticks.Time) { newNavigator.AddRecord(navigator.Current); } } return(Task.FromResult(newNavigator)); }
public async Task <TimeSerie <ITradeBar> > GetHistoryNavigator(TimeSpan resolution, DateTime historyStartTime) { if (historyStartTime > this.Time) { throw new InvalidOperationException("Requested future quotes"); } if (resolution != TimeSpan.FromMinutes(1)) { throw new NotSupportedException("Binance symbol history only supports resolution 1 minute"); } var history = new TimeSerie <ITradeBar>(); var sem = GetSemaphore(); await sem.WaitAsync(); try { //--- get the data from db await HistoryDb.AssureData(HistoryId, historyStartTime, this.Time); ISymbolHistory symbolHistory = HistoryDb.GetSymbolHistory(HistoryId, historyStartTime, DateTime.MaxValue); //HistoryDb.CloseFile(this.Market, Symbol.Key, TimeSpan.FromSeconds(60)); while (symbolHistory.Ticks.MoveNext()) { history.AddRecord(symbolHistory.Ticks.Current, true); } } catch (Exception ex) { Logger.Error("Exception during SymbolFeed.GetHistoryNavigator: {0}", ex.Message); } finally { sem.Release(); } return(history); }