fix a bit time logic and refresh of the graph

This commit is contained in:
Vasily.onl
2025-06-06 11:59:44 +08:00
parent 87843a1d35
commit 74b83d77fc
2 changed files with 34 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ import pandas as pd
from datetime import datetime, timezone
from typing import List, Dict, Any, Optional, Union
from decimal import Decimal
from tzlocal import get_localzone
from utils.logger import get_logger
@@ -114,10 +115,21 @@ def prepare_chart_data(candles: List[Dict[str, Any]]) -> pd.DataFrame:
# Convert to DataFrame
df = pd.DataFrame(candles)
# Ensure timestamp is datetime
# Ensure timestamp is datetime and localized to system time
if 'timestamp' in df.columns:
df['timestamp'] = pd.to_datetime(df['timestamp'])
local_tz = get_localzone()
# Check if the timestamps are already timezone-aware
if df['timestamp'].dt.tz is not None:
# If they are, just convert to the local timezone
df['timestamp'] = df['timestamp'].dt.tz_convert(local_tz)
logger.debug(f"Converted timezone-aware timestamps to local timezone: {local_tz}")
else:
# If they are naive, localize to UTC first, then convert
df['timestamp'] = df['timestamp'].dt.tz_localize('UTC').dt.tz_convert(local_tz)
logger.debug(f"Localized naive timestamps to UTC and converted to local timezone: {local_tz}")
# Convert OHLCV columns to numeric
numeric_columns = ['open', 'high', 'low', 'close']
if 'volume' in df.columns: