Reduce API call when fetching new candles
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user