timezones

This commit is contained in:
Dobromir Popov
2025-07-27 20:43:28 +03:00
parent 1636082ba3
commit 1894d453c9
5 changed files with 255 additions and 31 deletions

View File

@ -5899,25 +5899,44 @@ class CleanTradingDashboard:
# Ensure we have minimum required data (pad if necessary)
def pad_ohlcv_data(bars, target_count=300):
if len(bars) < target_count:
# Pad with the last bar repeated
# Pad with realistic variation instead of identical bars
if len(bars) > 0:
last_bar = bars[-1]
while len(bars) < target_count:
bars.append(last_bar)
# Add small random variation to prevent identical data
import random
for i in range(target_count - len(bars)):
# Create slight variations of the last bar
variation = random.uniform(-0.001, 0.001) # 0.1% variation
new_bar = OHLCVBar(
symbol=last_bar.symbol,
timestamp=last_bar.timestamp + timedelta(seconds=i),
open=last_bar.open * (1 + variation),
high=last_bar.high * (1 + variation),
low=last_bar.low * (1 + variation),
close=last_bar.close * (1 + variation),
volume=last_bar.volume * (1 + random.uniform(-0.1, 0.1)),
timeframe=last_bar.timeframe
)
bars.append(new_bar)
else:
# Create dummy bars if no data
# Create realistic dummy bars with variation
from core.data_models import OHLCVBar
dummy_bar = OHLCVBar(
symbol=symbol,
timestamp=datetime.now(),
open=3500.0,
high=3510.0,
low=3490.0,
close=3505.0,
volume=1000.0,
timeframe="1s"
)
bars = [dummy_bar] * target_count
base_price = 3500.0
for i in range(target_count):
# Add realistic price movement
price_change = random.uniform(-0.02, 0.02) # 2% max change
current_price = base_price * (1 + price_change)
dummy_bar = OHLCVBar(
symbol=symbol,
timestamp=datetime.now() - timedelta(seconds=target_count-i),
open=current_price * random.uniform(0.998, 1.002),
high=current_price * random.uniform(1.000, 1.005),
low=current_price * random.uniform(0.995, 1.000),
close=current_price,
volume=random.uniform(500.0, 2000.0),
timeframe="1s"
)
bars.append(dummy_bar)
return bars[:target_count] # Ensure exactly target_count
# Pad all data to required length