dash interval updated
This commit is contained in:
@ -121,7 +121,7 @@ class COBDashboardServer:
|
|||||||
|
|
||||||
# Initialize COB integration
|
# Initialize COB integration
|
||||||
self.cob_integration = COBIntegration(symbols=self.symbols)
|
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
|
# Start COB data streaming as background task
|
||||||
asyncio.create_task(self.cob_integration.start())
|
asyncio.create_task(self.cob_integration.start())
|
||||||
@ -319,6 +319,14 @@ class COBDashboardServer:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error handling WebSocket message: {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):
|
async def _on_cob_update(self, symbol: str, data: Dict):
|
||||||
"""Handle COB updates from integration"""
|
"""Handle COB updates from integration"""
|
||||||
try:
|
try:
|
||||||
@ -504,7 +512,7 @@ class COBDashboardServer:
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.websocket_connections.discard(ws)
|
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:
|
except Exception as e:
|
||||||
logger.error(f"Error in periodic stats update: {e}")
|
logger.error(f"Error in periodic stats update: {e}")
|
||||||
|
@ -778,10 +778,10 @@ class TradingDashboard:
|
|||||||
className="text-light mb-0 opacity-75 small")
|
className="text-light mb-0 opacity-75 small")
|
||||||
], className="bg-dark p-2 mb-2"),
|
], 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(
|
dcc.Interval(
|
||||||
id='interval-component',
|
id='interval-component',
|
||||||
interval=10000, # Update every 10 seconds for efficiency
|
interval=1000, # Update every 1 second for maximum responsiveness
|
||||||
n_intervals=0
|
n_intervals=0
|
||||||
),
|
),
|
||||||
|
|
||||||
@ -1035,9 +1035,9 @@ class TradingDashboard:
|
|||||||
update_start = time.time()
|
update_start = time.time()
|
||||||
|
|
||||||
try:
|
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_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_heavy_update = n_intervals % 10 == 0 # Heavy operations every 10s
|
||||||
is_cleanup_update = n_intervals % 60 == 0 # Cleanup every 60s
|
is_cleanup_update = n_intervals % 60 == 0 # Cleanup every 60s
|
||||||
|
|
||||||
@ -1143,12 +1143,12 @@ class TradingDashboard:
|
|||||||
# MEXC status (simple)
|
# 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"
|
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:
|
if is_chart_update:
|
||||||
try:
|
try:
|
||||||
if hasattr(self, '_cached_chart_data_time'):
|
if hasattr(self, '_cached_chart_data_time'):
|
||||||
cache_time = 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)
|
price_chart = getattr(self, '_cached_price_chart', None)
|
||||||
else:
|
else:
|
||||||
price_chart = self._create_price_chart_optimized(symbol, current_price)
|
price_chart = self._create_price_chart_optimized(symbol, current_price)
|
||||||
@ -1163,7 +1163,7 @@ class TradingDashboard:
|
|||||||
price_chart = getattr(self, '_cached_price_chart',
|
price_chart = getattr(self, '_cached_price_chart',
|
||||||
self._create_empty_chart("Chart Error", "Chart temporarily unavailable"))
|
self._create_empty_chart("Chart Error", "Chart temporarily unavailable"))
|
||||||
else:
|
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',
|
price_chart = getattr(self, '_cached_price_chart',
|
||||||
self._create_empty_chart("Loading", "Chart loading..."))
|
self._create_empty_chart("Loading", "Chart loading..."))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user