Add performance for price reminder
This commit is contained in:
@@ -96,9 +96,73 @@ public static class CandleHelpers
|
||||
return string.Join("-", exchange, ticker, timeframe);
|
||||
}
|
||||
|
||||
public static (TradingExchanges exchange, Ticker ticker, Timeframe timeframe) ParseCandleStoreGrainKey(string grainKey)
|
||||
public static (TradingExchanges exchange, Ticker ticker, Timeframe timeframe) ParseCandleStoreGrainKey(
|
||||
string grainKey)
|
||||
{
|
||||
var components = grainKey.Split('-');
|
||||
return (MiscExtensions.ParseEnum<TradingExchanges>(components[0]), MiscExtensions.ParseEnum<Ticker>(components[1]), MiscExtensions.ParseEnum<Timeframe>(components[2]));
|
||||
return (MiscExtensions.ParseEnum<TradingExchanges>(components[0]),
|
||||
MiscExtensions.ParseEnum<Ticker>(components[1]), MiscExtensions.ParseEnum<Timeframe>(components[2]));
|
||||
}
|
||||
|
||||
public static TimeSpan GetDueTimeForTimeframe(Timeframe timeframe, DateTime now)
|
||||
{
|
||||
var intervalMinutes = GetBaseIntervalInSeconds(timeframe) / 60;
|
||||
|
||||
// Calculate the next candle boundary
|
||||
var nextBoundary = GetNextCandleBoundary(now, intervalMinutes);
|
||||
|
||||
// Add 1 second to ensure we're after the candle closes
|
||||
var targetTime = nextBoundary.AddSeconds(1);
|
||||
|
||||
// Return the time difference
|
||||
return targetTime - now;
|
||||
}
|
||||
|
||||
private static DateTime GetNextCandleBoundary(DateTime now, double intervalMinutes)
|
||||
{
|
||||
// For different timeframes, we need to align to different boundaries
|
||||
if (intervalMinutes == 1) // OneMinute
|
||||
{
|
||||
return new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1);
|
||||
}
|
||||
else if (intervalMinutes == 5) // FiveMinutes
|
||||
{
|
||||
var minute = (now.Minute / 5) * 5;
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, now.Hour, minute, 0);
|
||||
return boundary.AddMinutes(5);
|
||||
}
|
||||
else if (intervalMinutes == 15) // FifteenMinutes
|
||||
{
|
||||
var minute = (now.Minute / 15) * 15;
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, now.Hour, minute, 0);
|
||||
return boundary.AddMinutes(15);
|
||||
}
|
||||
else if (intervalMinutes == 30) // ThirtyMinutes
|
||||
{
|
||||
var minute = (now.Minute / 30) * 30;
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, now.Hour, minute, 0);
|
||||
return boundary.AddMinutes(30);
|
||||
}
|
||||
else if (intervalMinutes == 60) // OneHour
|
||||
{
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0);
|
||||
return boundary.AddHours(1);
|
||||
}
|
||||
else if (intervalMinutes == 240) // FourHour
|
||||
{
|
||||
var hour = (now.Hour / 4) * 4;
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, hour, 0, 0);
|
||||
return boundary.AddHours(4);
|
||||
}
|
||||
else if (intervalMinutes == 1440) // OneDay
|
||||
{
|
||||
var boundary = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
|
||||
return boundary.AddDays(1);
|
||||
}
|
||||
|
||||
// Fallback to 5-minute intervals
|
||||
var fallbackMinute = (now.Minute / 5) * 5;
|
||||
var fallbackBoundary = new DateTime(now.Year, now.Month, now.Day, now.Hour, fallbackMinute, 0);
|
||||
return fallbackBoundary.AddMinutes(5);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user