136 lines
5.7 KiB
Python
136 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Timezone Fix with Data Fetching
|
|
|
|
This script tests timezone conversion by actually fetching data and checking timestamps.
|
|
"""
|
|
|
|
import asyncio
|
|
import pandas as pd
|
|
from datetime import datetime
|
|
from core.data_provider import DataProvider
|
|
|
|
async def test_timezone_with_data():
|
|
"""Test timezone conversion with actual data fetching"""
|
|
print("=== Testing Timezone Fix with Data Fetching ===")
|
|
|
|
# Initialize data provider
|
|
print("1. Initializing data provider...")
|
|
data_provider = DataProvider()
|
|
|
|
# Wait for initialization
|
|
await asyncio.sleep(2)
|
|
|
|
# Test direct Binance API call
|
|
print("\n2. Testing direct Binance API call:")
|
|
try:
|
|
# Call the internal Binance fetch method directly
|
|
df = data_provider._fetch_from_binance('ETH/USDT', '1h', 5)
|
|
|
|
if df is not None and not df.empty:
|
|
print(f" ✅ Got {len(df)} candles from Binance API")
|
|
|
|
# Check timezone
|
|
if 'timestamp' in df.columns:
|
|
first_timestamp = df['timestamp'].iloc[0]
|
|
last_timestamp = df['timestamp'].iloc[-1]
|
|
|
|
print(f" First timestamp: {first_timestamp}")
|
|
print(f" Last timestamp: {last_timestamp}")
|
|
|
|
# Check if timezone is Europe/Sofia
|
|
if hasattr(first_timestamp, 'tz') and first_timestamp.tz is not None:
|
|
timezone_str = str(first_timestamp.tz)
|
|
print(f" Timezone: {timezone_str}")
|
|
|
|
if 'Europe/Sofia' in timezone_str or 'EET' in timezone_str or 'EEST' in timezone_str:
|
|
print(f" ✅ Timezone is correct: {timezone_str}")
|
|
else:
|
|
print(f" ❌ Timezone is incorrect: {timezone_str}")
|
|
|
|
# Show UTC offset
|
|
if hasattr(first_timestamp, 'utcoffset') and first_timestamp.utcoffset() is not None:
|
|
offset_hours = first_timestamp.utcoffset().total_seconds() / 3600
|
|
print(f" UTC offset: {offset_hours:+.0f} hours")
|
|
|
|
if offset_hours == 2 or offset_hours == 3: # EET (+2) or EEST (+3)
|
|
print(" ✅ UTC offset is correct for Europe/Sofia")
|
|
else:
|
|
print(f" ❌ UTC offset is incorrect: {offset_hours:+.0f} hours")
|
|
|
|
# Compare with UTC time
|
|
print("\n Timestamp comparison:")
|
|
for i in range(min(2, len(df))):
|
|
row = df.iloc[i]
|
|
local_time = row['timestamp']
|
|
utc_time = local_time.astimezone(pd.Timestamp.now(tz='UTC').tz)
|
|
|
|
print(f" Local (Sofia): {local_time}")
|
|
print(f" UTC: {utc_time}")
|
|
print(f" Difference: {(local_time - utc_time).total_seconds() / 3600:+.0f} hours")
|
|
print()
|
|
else:
|
|
print(" ❌ No timestamp column found")
|
|
else:
|
|
print(" ❌ No data returned from Binance API")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error fetching from Binance: {e}")
|
|
|
|
# Test MEXC API call as well
|
|
print("\n3. Testing MEXC API call:")
|
|
try:
|
|
df = data_provider._fetch_from_mexc('ETH/USDT', '1h', 3)
|
|
|
|
if df is not None and not df.empty:
|
|
print(f" ✅ Got {len(df)} candles from MEXC API")
|
|
|
|
# Check timezone
|
|
if 'timestamp' in df.columns:
|
|
first_timestamp = df['timestamp'].iloc[0]
|
|
print(f" First timestamp: {first_timestamp}")
|
|
|
|
# Check timezone
|
|
if hasattr(first_timestamp, 'tz') and first_timestamp.tz is not None:
|
|
timezone_str = str(first_timestamp.tz)
|
|
print(f" Timezone: {timezone_str}")
|
|
|
|
if 'Europe/Sofia' in timezone_str or 'EET' in timezone_str or 'EEST' in timezone_str:
|
|
print(f" ✅ MEXC timezone is correct: {timezone_str}")
|
|
else:
|
|
print(f" ❌ MEXC timezone is incorrect: {timezone_str}")
|
|
|
|
# Show UTC offset
|
|
if hasattr(first_timestamp, 'utcoffset') and first_timestamp.utcoffset() is not None:
|
|
offset_hours = first_timestamp.utcoffset().total_seconds() / 3600
|
|
print(f" UTC offset: {offset_hours:+.0f} hours")
|
|
else:
|
|
print(" ❌ No data returned from MEXC API")
|
|
|
|
except Exception as e:
|
|
print(f" ❌ Error fetching from MEXC: {e}")
|
|
|
|
# Show current timezone info
|
|
print(f"\n4. Current timezone information:")
|
|
import pytz
|
|
sofia_tz = pytz.timezone('Europe/Sofia')
|
|
current_sofia = datetime.now(sofia_tz)
|
|
current_utc = datetime.now(pytz.UTC)
|
|
|
|
print(f" Current Sofia time: {current_sofia}")
|
|
print(f" Current UTC time: {current_utc}")
|
|
print(f" Time difference: {(current_sofia - current_utc).total_seconds() / 3600:+.0f} hours")
|
|
|
|
# Check if it's summer time (EEST) or winter time (EET)
|
|
offset_hours = current_sofia.utcoffset().total_seconds() / 3600
|
|
if offset_hours == 3:
|
|
print(" ✅ Currently in EEST (Eastern European Summer Time)")
|
|
elif offset_hours == 2:
|
|
print(" ✅ Currently in EET (Eastern European Time)")
|
|
else:
|
|
print(f" ❌ Unexpected offset: {offset_hours:+.0f} hours")
|
|
|
|
print("\n✅ Timezone fix test with data completed!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_timezone_with_data()) |