Reduce API call when fetching new candles

This commit is contained in:
2025-09-17 17:45:41 +07:00
parent 900405b3de
commit 841bb20800
3 changed files with 85 additions and 12 deletions

View File

@@ -70,9 +70,6 @@ public class PriceFetcherGrain : Grain, IPriceFetcherGrain, IRemindable
dueTime,
TimeSpan.FromMinutes(intervalMinutes));
// Optional immediate kick-off to avoid waiting until next boundary
_ = FetchAndPublishPricesAsync();
await base.OnActivateAsync(cancellationToken);
}
@@ -134,6 +131,15 @@ public class PriceFetcherGrain : Grain, IPriceFetcherGrain, IRemindable
var isFirstCall = !existingCandles.Any();
// Check if the next expected candle is available yet
var nextExpectedCandleTime = CandleHelpers.GetNextExpectedCandleTime(timeframe);
if (nextExpectedCandleTime > DateTime.UtcNow)
{
_logger.LogDebug("Next candle for {Exchange}-{Ticker}-{Timeframe} not available yet. Expected at {NextCandleTime}, current time: {CurrentTime}",
exchange, ticker, timeframe, nextExpectedCandleTime, DateTime.UtcNow);
return; // Skip this fetch as the new candle won't be available
}
var startDate = !isFirstCall
? existingCandles.Last().Date
: new DateTime(2017, 1, 1);