/// <summary> /// Finds out the oldest stored candle's timestamp (if any). /// </summary> /// <param name="assetPairId"></param> /// <param name="priceType"></param> /// <param name="interval"></param> /// <returns>The oldest candle or null./></returns> /// <exception cref="InvalidOperationException">If the specified asset pair is not currently supported by storage.</exception> public async Task <ICandle> TryGetOldestCandleAsync(string assetPairId, CandlePriceType priceType, CandleTimeInterval interval) { CheckupAssetPairOrFail(assetPairId); var firstCandle = await _candlesHistoryRepository.TryGetFirstCandleAsync(assetPairId, interval, priceType); return(firstCandle); // The risk of the null is minimal but not excluded. }
// Calculating the earliest and the latest dates for the biggest interval candles fetching public async Task <(DateTime dateFrom, DateTime dateTo)> GetDateTimeRangeAsync(string assetPairId, CandlePriceType priceType) { var firstBiggestCandle = await _candlesHistoryRepository.TryGetFirstCandleAsync(assetPairId, Constants.DbStoredIntervals.Last(), priceType); // If we have no such a candle in repository, we return fake dates for further decision making in the caller code if (firstBiggestCandle == null) { return(dateFrom : DateTime.MinValue, dateTo : DateTime.MinValue); } var dtFrom = firstBiggestCandle.Timestamp; // The first candle's in storage timestamp var dtTo = DateTime.UtcNow.TruncateTo(CandleTimeInterval.Month); // The begining of the current month (for further candles reading with exclusive upper date-time border). return(dateFrom : dtFrom, dateTo : dtTo); }
public async Task <ICandle> GetFirstCandleOfHistoryAsync(string assetPair, CandlePriceType priceType) { var candle = await _candlesHistoryRepository.TryGetFirstCandleAsync(assetPair, CandleTimeInterval.Sec, priceType); return(candle); }