private async Task CatchupAsync(Candle lastDbCandle) { var maxPoints = _exchange.ExchangeConfig.UserConfig.MaxDataPoints; var now = _exchange.Now; var dataPoints = lastDbCandle != null ? ExchangeUtils.GetDataPointsFromTimeSpan(_period, now - lastDbCandle.Timestamp.ToUniversalTime()) : maxPoints; if (dataPoints <= 0) { return; } if (dataPoints > maxPoints) { dataPoints = maxPoints; } var candles = await _exchange.GetCandlesAsync(_instrument, _period, ExchangeUtils.GetTimeOffsetFromDataPoints(_period, now, dataPoints), now); if (candles != null) { await InsertCandlesAsync(candles.ToArray()); } var lastEntryLogText = (lastDbCandle != null ? $"was last seen at {lastDbCandle.Timestamp.ToUniversalTime()}" : "has no pevious records"); _logger.Log(LogLevel.Info, $"{_exchangeName} {_instrument} {_period} {lastEntryLogText}"); var syncStatusText = (dataPoints > 0 ? $"{dataPoints} data points behind" : "up to date"); _logger.Log(LogLevel.Info, $"{_exchangeName} {_instrument} {_period} is {syncStatusText}"); }
private void ResetCurrentCandle(CandleDto latest) { CurrentCandle.Open = latest.Close; CurrentCandle.High = latest.Close; CurrentCandle.Low = latest.Close; CurrentCandle.Trades = 0; CurrentCandle.Volume = 0; CurrentCandle.Timestamp = ExchangeUtils.GetTimeOffsetFromDataPoints(latest.Period, CurrentCandle.Timestamp, -1); }