diff --git a/web/cob_realtime_dashboard.py b/web/cob_realtime_dashboard.py index ab56fdd..ae67d9e 100644 --- a/web/cob_realtime_dashboard.py +++ b/web/cob_realtime_dashboard.py @@ -121,7 +121,7 @@ class COBDashboardServer: # Initialize COB integration self.cob_integration = COBIntegration(symbols=self.symbols) - self.cob_integration.add_dashboard_callback(self._on_cob_update) + self.cob_integration.add_dashboard_callback(self._sync_cob_update_wrapper) # Start COB data streaming as background task asyncio.create_task(self.cob_integration.start()) @@ -319,6 +319,14 @@ class COBDashboardServer: except Exception as e: logger.error(f"Error handling WebSocket message: {e}") + def _sync_cob_update_wrapper(self, symbol: str, data: Dict): + """Sync wrapper for async COB update handler""" + try: + # Create async task to handle the update + asyncio.create_task(self._on_cob_update(symbol, data)) + except Exception as e: + logger.error(f"Error in COB update wrapper for {symbol}: {e}") + async def _on_cob_update(self, symbol: str, data: Dict): """Handle COB updates from integration""" try: @@ -504,7 +512,7 @@ class COBDashboardServer: except Exception: self.websocket_connections.discard(ws) - await asyncio.sleep(5) # Update every 5 seconds + await asyncio.sleep(1) # Update every 1 second for real-time responsiveness except Exception as e: logger.error(f"Error in periodic stats update: {e}") diff --git a/web/dashboard.py b/web/dashboard.py index 012451c..78c30c0 100644 --- a/web/dashboard.py +++ b/web/dashboard.py @@ -778,10 +778,10 @@ class TradingDashboard: className="text-light mb-0 opacity-75 small") ], className="bg-dark p-2 mb-2"), - # Auto-refresh component - optimized for efficient updates + # Auto-refresh component - ultra-fast updates for real-time trading dcc.Interval( id='interval-component', - interval=10000, # Update every 10 seconds for efficiency + interval=1000, # Update every 1 second for maximum responsiveness n_intervals=0 ), @@ -1035,9 +1035,9 @@ class TradingDashboard: update_start = time.time() try: - # Smart update scheduling - different frequencies for different components + # Smart update scheduling - optimized for 1s responsiveness is_price_update = True # Price updates every interval (1s) - is_chart_update = n_intervals % 5 == 0 # Chart updates every 5s + is_chart_update = True # Chart updates every 1s for real-time feel is_heavy_update = n_intervals % 10 == 0 # Heavy operations every 10s is_cleanup_update = n_intervals % 60 == 0 # Cleanup every 60s @@ -1143,12 +1143,12 @@ class TradingDashboard: # MEXC status (simple) mexc_status = "LIVE" if (self.trading_executor and self.trading_executor.trading_enabled and not self.trading_executor.simulation_mode) else "SIM" - # CHART OPTIMIZATION - Only update charts every 5 seconds + # CHART OPTIMIZATION - Real-time chart updates every 1 second if is_chart_update: try: if hasattr(self, '_cached_chart_data_time'): cache_time = self._cached_chart_data_time - if time.time() - cache_time < 20: # Use cached chart if < 20s old + if time.time() - cache_time < 5: # Use cached chart if < 5s old for faster updates price_chart = getattr(self, '_cached_price_chart', None) else: price_chart = self._create_price_chart_optimized(symbol, current_price) @@ -1163,7 +1163,7 @@ class TradingDashboard: price_chart = getattr(self, '_cached_price_chart', self._create_empty_chart("Chart Error", "Chart temporarily unavailable")) else: - # Use cached chart + # Use cached chart (should not happen since is_chart_update is always True now) price_chart = getattr(self, '_cached_price_chart', self._create_empty_chart("Loading", "Chart loading..."))