device fix , TZ fix

This commit is contained in:
Dobromir Popov
2025-07-27 22:13:28 +03:00
parent 9e1684f9f8
commit 368c49df50
6 changed files with 194 additions and 163 deletions

View File

@ -1478,7 +1478,11 @@ class DataProvider:
# Check for cached data and determine what we need to fetch
cached_data = self._load_monthly_data_from_cache(symbol)
end_time = datetime.utcnow()
import pytz
utc = pytz.UTC
sofia_tz = pytz.timezone('Europe/Sofia')
end_time = datetime.utcnow().replace(tzinfo=utc).astimezone(sofia_tz)
start_time = end_time - timedelta(days=30)
if cached_data is not None and not cached_data.empty:
@ -1496,6 +1500,12 @@ class DataProvider:
# Check if we need to fill gaps
gap_start = cache_end + timedelta(minutes=1)
# Ensure gap_start has same timezone as end_time for comparison
if gap_start.tzinfo is None:
gap_start = sofia_tz.localize(gap_start)
elif gap_start.tzinfo != sofia_tz:
gap_start = gap_start.astimezone(sofia_tz)
if gap_start < end_time:
# Need to fill gap from cache_end to now
logger.info(f"Filling gap from {gap_start} to {end_time}")
@ -1573,8 +1583,10 @@ class DataProvider:
'taker_buy_quote', 'ignore'
])
# Process columns
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
# Process columns with proper timezone handling
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms', utc=True)
# Convert from UTC to Europe/Sofia timezone to match cached data
df['timestamp'] = df['timestamp'].dt.tz_convert('Europe/Sofia')
for col in ['open', 'high', 'low', 'close', 'volume']:
df[col] = df[col].astype(float)
@ -1644,8 +1656,10 @@ class DataProvider:
'taker_buy_quote', 'ignore'
])
# Process columns
batch_df['timestamp'] = pd.to_datetime(batch_df['timestamp'], unit='ms')
# Process columns with proper timezone handling
batch_df['timestamp'] = pd.to_datetime(batch_df['timestamp'], unit='ms', utc=True)
# Convert from UTC to Europe/Sofia timezone to match cached data
batch_df['timestamp'] = batch_df['timestamp'].dt.tz_convert('Europe/Sofia')
for col in ['open', 'high', 'low', 'close', 'volume']:
batch_df[col] = batch_df[col].astype(float)