Fix datetime
This commit is contained in:
@@ -42,11 +42,7 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
|
||||
// Parse the grain key to extract exchange, ticker, and timeframe
|
||||
var (exchange, ticker, timeframe) = CandleHelpers.ParseCandleStoreGrainKey(grainKey);
|
||||
|
||||
// Initialize state if empty
|
||||
if (_state.State.Candles == null || _state.State.Candles.Count == 0)
|
||||
{
|
||||
await LoadInitialCandlesAsync(exchange, ticker, timeframe);
|
||||
}
|
||||
await LoadInitialCandlesAsync(exchange, ticker, timeframe);
|
||||
|
||||
// Subscribe to the price stream
|
||||
await SubscribeToPriceStreamAsync(grainKey);
|
||||
@@ -55,7 +51,8 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during CandleStoreGrain activation for key: {GrainKey}", this.GetPrimaryKeyString());
|
||||
_logger.LogError(ex, "Error during CandleStoreGrain activation for key: {GrainKey}",
|
||||
this.GetPrimaryKeyString());
|
||||
|
||||
// Ensure state is initialized even if there's an error
|
||||
if (_state.State.Candles == null)
|
||||
@@ -87,7 +84,8 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
|
||||
// Ensure state is initialized
|
||||
if (_state.State.Candles == null)
|
||||
{
|
||||
_logger.LogWarning("State not initialized for grain {GrainKey}, returning empty list", this.GetPrimaryKeyString());
|
||||
_logger.LogWarning("State not initialized for grain {GrainKey}, returning empty list",
|
||||
this.GetPrimaryKeyString());
|
||||
return Task.FromResult(new List<Candle>());
|
||||
}
|
||||
|
||||
@@ -168,7 +166,8 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
|
||||
var endDate = DateTime.UtcNow;
|
||||
var startDate = CandleHelpers.GetBotPreloadSinceFromTimeframe(timeframe);
|
||||
|
||||
var candles = await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate, endDate, MaxCandleCount);
|
||||
var candles =
|
||||
await _candleRepository.GetCandles(exchange, ticker, timeframe, startDate, endDate, MaxCandleCount);
|
||||
|
||||
if (candles?.Any() == true)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ public class DateHelpers
|
||||
{
|
||||
public static DateTime GetFromUnixTimestamp(int unixTimestamp)
|
||||
{
|
||||
var dat_Time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local);
|
||||
var dat_Time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
return dat_Time.AddSeconds(unixTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ public static class PriceExtensions
|
||||
{
|
||||
public static List<Candle> GetCandles(this Round[] prices, Timeframe timeframe, Ticker ticker)
|
||||
{
|
||||
int timezoneOffset = -(int)(new DateTimeOffset(DateTime.UtcNow).Offset.TotalSeconds);
|
||||
var CHART_PERIODS = new Dictionary<Timeframe, int>
|
||||
{
|
||||
{ Timeframe.FiveMinutes, 60 * 5 },
|
||||
@@ -41,8 +40,8 @@ public static class PriceExtensions
|
||||
{
|
||||
candles.Add(new Candle
|
||||
{
|
||||
OpenTime = DateHelpers.GetFromUnixTimestamp(prevTsGroup + timezoneOffset),
|
||||
Date = DateHelpers.GetFromUnixTimestamp(tsGroup + timezoneOffset),
|
||||
OpenTime = DateHelpers.GetFromUnixTimestamp(prevTsGroup),
|
||||
Date = DateHelpers.GetFromUnixTimestamp(tsGroup),
|
||||
Open = o,
|
||||
High = h,
|
||||
Low = l,
|
||||
|
||||
Reference in New Issue
Block a user