private OhlcData RequestInternal(TimeRange timeRange, bool allowLive = false) { if (!_apiAdapters.Any() && !_storageAdapters.Any()) { return(null); } if (!StorageEnabled && !ApiEnabled) { return(null); } lock (_lock) { OhlcData results = null; if (StorageEnabled) { results = ContinuousOrMergedStorage(timeRange, allowLive); } var hasRemaining = results.IsEmpty() ? null : results.Remaining(timeRange); if (ApiEnabled && (results.IsEmpty() || hasRemaining != null)) { results = CollectApi(hasRemaining ?? timeRange, results); } Ctx.Status(results.IsNotEmpty() ? "Data received, processing." : "No data received."); if (StorageEnabled && results.IsNotEmpty()) { StoreResults(timeRange, results); } return(results); } }
public virtual OhlcData Include(TimeRange rangeAttempted, OhlcData data, bool acceptLiveRange = false) { var range = data.GetTimeRange(rangeAttempted.TimeResolution); if (!acceptLiveRange) { range = range.RemoveLiveRange(); rangeAttempted = rangeAttempted.RemoveLiveRange(); } if (data.IsNotEmpty()) { Found.Add(range); } else { Unavailable.Add(rangeAttempted); } if (!Unavailable.Covers(rangeAttempted) && !Found.Covers(rangeAttempted)) { Requested.Add(rangeAttempted); } var foundMin = Found.MinimumFrom(); var missingMin = Unavailable.MinimumFrom(); var minDate = foundMin < missingMin ? foundMin : missingMin; if (minDate != DateTime.MaxValue) { UtcEarliestEntry = UtcEarliestEntry > minDate ? minDate : UtcEarliestEntry; } return(data); }