tter cache
This commit is contained in:
parent
7e4b29fdc2
commit
5a30c5721d
@ -278,6 +278,30 @@ class TradingDashboard:
|
||||
# Load available models for real trading
|
||||
self._load_available_models()
|
||||
|
||||
# Preload essential data to prevent excessive API calls during dashboard updates
|
||||
logger.info("Preloading essential market data to cache...")
|
||||
try:
|
||||
# Preload key timeframes for main symbols to ensure cache is populated
|
||||
symbols_to_preload = self.config.symbols or ['ETH/USDT', 'BTC/USDT']
|
||||
timeframes_to_preload = ['1m', '1h', '1d'] # Skip 1s since we use WebSocket for that
|
||||
|
||||
for symbol in symbols_to_preload[:2]: # Limit to first 2 symbols
|
||||
for timeframe in timeframes_to_preload:
|
||||
try:
|
||||
# Load data into cache (refresh=True for initial load, then cache will be used)
|
||||
df = self.data_provider.get_historical_data(symbol, timeframe, limit=100, refresh=True)
|
||||
if df is not None and not df.empty:
|
||||
logger.info(f"Preloaded {len(df)} {timeframe} bars for {symbol}")
|
||||
else:
|
||||
logger.warning(f"Failed to preload data for {symbol} {timeframe}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Error preloading {symbol} {timeframe}: {e}")
|
||||
|
||||
logger.info("Preloading completed - cache populated for frequent queries")
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Error during preloading: {e}")
|
||||
|
||||
# Create Dash app
|
||||
self.app = dash.Dash(__name__, external_stylesheets=[
|
||||
'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css',
|
||||
@ -829,7 +853,7 @@ class TradingDashboard:
|
||||
else:
|
||||
# Only try fresh API call if we have no data at all
|
||||
try:
|
||||
fresh_data = self.data_provider.get_historical_data(symbol, '1m', limit=1, refresh=True)
|
||||
fresh_data = self.data_provider.get_historical_data(symbol, '1m', limit=1, refresh=False)
|
||||
if fresh_data is not None and not fresh_data.empty:
|
||||
current_price = float(fresh_data['close'].iloc[-1])
|
||||
data_source = "API"
|
||||
@ -4571,7 +4595,7 @@ class TradingDashboard:
|
||||
symbol=target_symbol,
|
||||
timeframe='1m',
|
||||
limit=50,
|
||||
refresh=True
|
||||
refresh=False # Use cache to prevent excessive API calls
|
||||
)
|
||||
else:
|
||||
# Get historical data for other timeframes
|
||||
@ -4579,7 +4603,7 @@ class TradingDashboard:
|
||||
symbol=target_symbol,
|
||||
timeframe=timeframe,
|
||||
limit=50, # Last 50 bars
|
||||
refresh=True
|
||||
refresh=False # Use cache to prevent excessive API calls
|
||||
)
|
||||
|
||||
if df is not None and not df.empty and len(df) >= 10:
|
||||
@ -4608,7 +4632,7 @@ class TradingDashboard:
|
||||
symbol='BTC/USDT',
|
||||
timeframe='1m',
|
||||
limit=50,
|
||||
refresh=True
|
||||
refresh=False # Use cache to prevent excessive API calls
|
||||
)
|
||||
|
||||
if btc_1s_df is not None and not btc_1s_df.empty and len(btc_1s_df) >= 10:
|
||||
|
Loading…
x
Reference in New Issue
Block a user