protected override Task <bool> CanGetImpl <T>(TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveOptions) { var chunks = HistoricalDataChunkRangeProvider.GetBarChunks(start, endExclusive, timeFrame); foreach (var chunk in chunks) { } //throw new NotImplementedException(); // TODO return(Task.FromResult(true)); }
protected override async Task <T[]?> GetImpl <T>(TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveParameters) { HistoricalDataMemoryCacheKey?memoryCacheKey; if (Options.UseMemoryCache) { memoryCacheKey = new HistoricalDataMemoryCacheKey { Type = typeof(T), Symbol = symbol, Start = start, EndExclusive = endExclusive, Exchange = retrieveParameters.Exchange, ExchangeArea = retrieveParameters.ExchangeArea, }; if (ManualSingleton <HistoricalDataMemoryCache <T> > .GuaranteedInstance.Dict.TryGetValue(memoryCacheKey, out var value)) { Logger.LogTrace($"[cache hit] {memoryCacheKey}"); // TODO TOTELEMETRY - counter for memory cache hit return(value); } } else { memoryCacheKey = null; Logger.LogTrace($"[CACHE MISS] {timeFrame} {symbol} {start} {endExclusive}"); // TODO TOTELEMETRY - counter for memory cache miss } if (LocalNetwork != null) { T[]? result; foreach (var c in LocalNetwork) { result = await c.Get <T>(timeFrame, symbol, start, endExclusive, retrieveParameters).ConfigureAwait(false); OnResult(result); return(result); } } var chunks = HistoricalDataChunkRangeProvider.GetBarChunks(start, endExclusive, timeFrame); var lists = new List <T[]>(); int totalBars = 0; foreach (var chunk in chunks) { var chunkData = await GetChunkImpl <T>(timeFrame, symbol, chunk.Item1, chunk.Item2, retrieveParameters).ConfigureAwait(false); lists.Add(chunkData); totalBars += chunkData.Length; } //if (retrieveOptions.OptimizeForBacktest && result.Count > 1) //{ var combined = new List <T>(totalBars); foreach (var list in lists) { combined.AddRange(list); } var combinedArray = combined.ToArray(); OnResult(combinedArray); void OnResult(T[]?result) { if (Options.UseMemoryCache) { ManualSingleton <HistoricalDataMemoryCache <T> > .GuaranteedInstance.Dict[memoryCacheKey] = result; } } return(combinedArray); //} }