/// <summary> /// Used for benchmarking. /// </summary> public List <OHLCBar> GetExternalData(int externalInstrumentID, DateTime startTime, DateTime endTime) { if (!_useExternalDataSource) { _logger.Log(LogLevel.Info, string.Format("Request for external data on instrument with external ID {0} not fulfilled, external data not allowed.", externalInstrumentID)); return(new List <OHLCBar>()); } return(ExternalDataSource.GetData(externalInstrumentID, startTime, endTime)); }
public List <OHLCBar> GetData(Instrument inst, DateTime startTime, DateTime endTime, BarSize frequency = BarSize.OneDay) { _logger.Log(LogLevel.Info, string.Format("Data request for {0} from {1} to {2} @ {3}", inst, startTime, endTime, frequency)); //Check the cache lock (_dataCacheLock) { if (_dataCache.ContainsKey(inst.ID) && _dataCache[inst.ID].First().DT <= startTime && _dataCache[inst.ID].Last().DT >= endTime) { _logger.Log(LogLevel.Info, "Found data in cache"); return(_dataCache[inst.ID].Where(x => x.DT >= startTime && x.DT <= endTime).ToList()); } } //if external data is not allowed, just grab the prior positions data if (!_useExternalDataSource) { return(GetLocalData(inst, startTime, endTime)); } //If the cache is not enough, go to the external datasource var data = ExternalDataSource.GetData(inst, startTime, endTime); //External datasource didn't have anything, get data from prior positions if (data == null || data.Count == 0) { _logger.Log(LogLevel.Info, "Data was not available externally, getting it form prior positions"); return(GetLocalData(inst, startTime, endTime)); } //QDMS data does NOT cover the entire period requested. //Try to supplement the data with the prices from prior positions if (frequency == BarSize.OneDay && (data.First().DT.Date > startTime.Date || data.Last().DT.Date < endTime)) { SupplementWithLocalData(inst, startTime, endTime, ref data); } AddToCache(data, inst.ID); return(data); }