コード例 #1
0
 protected override Task <bool> CanGetImpl <T>(TimeFrame timeFrame, string symbol, DateTime Start, DateTime endExclusive, HistoricalDataQueryParameters retrieveOptions)
 {
     throw new NotImplementedException();
 }
コード例 #2
0
 protected override Task <T[]?> GetImpl <T>(TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveOptions)
 => ClusterClient.GetGrain <HistoricalDataChunkGrain>(
     HistoricalDataChunkGrainKey.GetKey(timeFrame, symbol, start, endExclusive, retrieveOptions.Exchange, retrieveOptions.ExchangeArea, typeof(Binance.BinanceFuturesKlineItem))
     )
 .Get <T>(retrieveOptions.Options);
コード例 #3
0
 public Task Save <T>(string sourceId, T[] data, TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveParameters)
 {
     throw new NotImplementedException();
 }
コード例 #4
0
 private Task OnRetrievedFromInternet <T>(string sourceId, T[] data, TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveParameters)
 => LocalDiskWriter == null ? Task.CompletedTask
         : LocalDiskWriter.Save(sourceId, data, timeFrame, symbol, start, endExclusive, retrieveParameters);
コード例 #5
0
    protected async Task <T[]?> GetChunkImpl <T>(TimeFrame timeFrame, string symbol, DateTime start, DateTime endExclusive, HistoricalDataQueryParameters retrieveParameters)
    {
        //HistoricalDataChunkRangeProvider.ValidateIsChunkBoundary(start, endExclusive, timeFrame);
        // TODO:
        //
        // Try reading from disk (if disk reader present)
        // If not present, run the Retrieve Job,
        // write it to disk

        T[]? result;

        if (LocalDiskSources != null)
        {
            foreach (var c in LocalDiskSources)
            {
                result = await c.Get <T>(timeFrame, symbol, start, endExclusive, retrieveParameters).ConfigureAwait(false);

                if (result != null)
                {
                    // TOTELEMETRY - disk cache hit
                    return(result);
                }
            }
            // TOTELEMETRY - disk cache miss
        }

        {
            var exchangeSource = Exchange.TryGetValue(retrieveParameters.Exchange ?? throw new ArgumentNullException(nameof(retrieveParameters.Exchange)));
            if (exchangeSource != null)
            {
                result = await exchangeSource.Get <T>(timeFrame, symbol, start, endExclusive, retrieveParameters).ConfigureAwait(false);

                if (result != null)
                {
                    // TOTELEMETRY - exchange retrieve
                    OnRetrievedFromInternet(exchangeSource.SourceId, result, timeFrame, symbol, start, endExclusive, retrieveParameters);
                    return(result);
                }
            }
        }

        {
            var thirdPartySources = ThirdParty.TryGetValue(retrieveParameters.Exchange);
            if (thirdPartySources != null)
            {
                foreach (var source in thirdPartySources)
                {
                    result = await source.Get <T>(timeFrame, symbol, start, endExclusive, retrieveParameters).ConfigureAwait(false);

                    if (result != null)
                    {
                        // TOTELEMETRY - third party retrieve
                        OnRetrievedFromInternet(source.SourceId, result, timeFrame, symbol, start, endExclusive, retrieveParameters);
                        return(result);
                    }
                }
            }
        }

        return(null);
    }
コード例 #6
0
    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);

        //}
    }
コード例 #7
0
    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));
    }