private bool ProcessSecCandles(IEnumerable <ICandle> secCandles)
        {
            foreach (var candle in secCandles)
            {
                if (_cts.IsCancellationRequested)
                {
                    return(true);
                }

                if (_healthService.CandlesToDispatchQueueLength > _settings.CandlesToDispatchLengthThrottlingThreshold)
                {
                    try
                    {
                        Task.Delay(_settings.ThrottlingDelay).GetAwaiter().GetResult();
                    }
                    catch (TaskCanceledException)
                    {
                        return(true);
                    }
                }

                _telemetryService.UpdateCurrentHistoryDate(candle.Timestamp, candle.PriceType);

                CheckCandleOrder(candle);

                _candlesPersistenceQueue.EnqueueCandle(candle);

                _intervalsToGenerate
                .AsParallel()
                .ForAll(interval =>
                {
                    var mergingResult = _candlesGenerator.Merge(
                        assetPair: candle.AssetPairId,
                        priceType: candle.PriceType,
                        timeInterval: interval,
                        timestamp: candle.Timestamp,
                        open: candle.Open,
                        close: candle.Close,
                        low: candle.Low,
                        high: candle.High);

                    if (mergingResult.WasChanged)
                    {
                        _candlesPersistenceQueue.EnqueueCandle(mergingResult.Candle);
                    }
                });
            }

            return(false);
        }
예제 #2
0
        public Task ProcessCandlesAsync(IReadOnlyList <ICandle> candles)
        {
            if (!candles.Any())
            {
                return(Task.CompletedTask);
            }

            var cacheTask = _candlesCacheService.CacheAsync(candles);

            foreach (var candle in candles)
            {
                _candlesPersistenceQueue.EnqueueCandle(candle);
            }

            return(cacheTask);
        }
예제 #3
0
        public Task ProcessCandlesAsync(IReadOnlyList <ICandle> candles)
        {
            if (!candles.Any())
            {
                return(Task.CompletedTask);
            }

            var cacheTask = _candlesCacheService.CacheAsync(candles.Where(x => Constants.RedisIntervals.Contains(x.TimeInterval)).ToArray());

            foreach (var candle in candles.Where(x => Constants.DbStoredIntervals.Contains(x.TimeInterval)))
            {
                _candlesPersistenceQueue.EnqueueCandle(candle);
            }

            return(cacheTask);
        }