cob update fix
This commit is contained in:
@ -141,6 +141,31 @@ class CleanTradingDashboard:
|
||||
self.orchestrator.set_trading_executor(self.trading_executor)
|
||||
logger.info("Trading executor connected to orchestrator for signal execution")
|
||||
|
||||
# Connect dashboard to orchestrator for COB data updates
|
||||
if hasattr(self.orchestrator, 'set_dashboard'):
|
||||
self.orchestrator.set_dashboard(self)
|
||||
logger.info("✅ Dashboard connected to orchestrator for COB data updates")
|
||||
|
||||
# Start orchestrator's real-time processing to ensure COB data flows
|
||||
if hasattr(self.orchestrator, 'start_continuous_trading'):
|
||||
try:
|
||||
# Start in background thread to avoid blocking dashboard startup
|
||||
import threading
|
||||
def start_orchestrator_trading():
|
||||
try:
|
||||
import asyncio
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
loop.run_until_complete(self.orchestrator.start_continuous_trading())
|
||||
except Exception as e:
|
||||
logger.error(f"Error starting orchestrator trading: {e}")
|
||||
|
||||
trading_thread = threading.Thread(target=start_orchestrator_trading, daemon=True)
|
||||
trading_thread.start()
|
||||
logger.info("✅ Started orchestrator real-time processing for COB data")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start orchestrator trading: {e}")
|
||||
|
||||
# Initialize enhanced training system for predictions
|
||||
self.training_system = None
|
||||
self._initialize_enhanced_training_system()
|
||||
@ -292,6 +317,23 @@ class CleanTradingDashboard:
|
||||
def _on_cob_data_update(self, symbol: str, cob_data: dict):
|
||||
"""Handle COB data updates from data provider"""
|
||||
try:
|
||||
# Also update the COB cache for status display
|
||||
if not hasattr(self, 'cob_cache'):
|
||||
self.cob_cache = {}
|
||||
|
||||
if symbol not in self.cob_cache:
|
||||
self.cob_cache[symbol] = {'last_update': 0, 'data': None, 'updates_count': 0}
|
||||
|
||||
# Update cache
|
||||
self.cob_cache[symbol]['data'] = cob_data
|
||||
self.cob_cache[symbol]['last_update'] = time.time()
|
||||
self.cob_cache[symbol]['updates_count'] += 1
|
||||
self.cob_cache[symbol]['websocket_status'] = 'connected'
|
||||
self.cob_cache[symbol]['source'] = 'data_provider'
|
||||
|
||||
logger.info(f"📊 Updated COB cache for {symbol} from data provider (updates: {self.cob_cache[symbol]['updates_count']})")
|
||||
|
||||
# Continue with existing logic
|
||||
# Update latest COB data cache
|
||||
if not hasattr(self, 'latest_cob_data'):
|
||||
self.latest_cob_data = {}
|
||||
@ -6498,6 +6540,42 @@ class CleanTradingDashboard:
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error initializing Enhanced COB Integration: {e}")
|
||||
|
||||
def update_cob_data_from_orchestrator(self, symbol: str, cob_data: Dict):
|
||||
"""Update COB cache from orchestrator data - called by orchestrator"""
|
||||
try:
|
||||
# Initialize cache if needed
|
||||
if not hasattr(self, 'cob_cache'):
|
||||
self.cob_cache = {}
|
||||
|
||||
if symbol not in self.cob_cache:
|
||||
self.cob_cache[symbol] = {'last_update': 0, 'data': None, 'updates_count': 0}
|
||||
|
||||
# Update cache with orchestrator data
|
||||
self.cob_cache[symbol]['data'] = cob_data
|
||||
self.cob_cache[symbol]['last_update'] = time.time()
|
||||
self.cob_cache[symbol]['updates_count'] += 1
|
||||
|
||||
# Set WebSocket status based on data source
|
||||
if isinstance(cob_data, dict) and 'stats' in cob_data:
|
||||
source = cob_data['stats'].get('source', 'unknown')
|
||||
if 'websocket' in source.lower():
|
||||
self.cob_cache[symbol]['websocket_status'] = 'connected'
|
||||
self.cob_cache[symbol]['source'] = source
|
||||
elif 'rest' in source.lower() or 'fallback' in source.lower():
|
||||
self.cob_cache[symbol]['websocket_status'] = 'fallback'
|
||||
self.cob_cache[symbol]['source'] = source
|
||||
else:
|
||||
self.cob_cache[symbol]['websocket_status'] = 'unknown'
|
||||
self.cob_cache[symbol]['source'] = source
|
||||
else:
|
||||
self.cob_cache[symbol]['websocket_status'] = 'connected'
|
||||
self.cob_cache[symbol]['source'] = 'orchestrator'
|
||||
|
||||
logger.info(f"📊 Updated COB cache for {symbol} from orchestrator: {self.cob_cache[symbol]['websocket_status']} (updates: {self.cob_cache[symbol]['updates_count']})")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error updating COB cache from orchestrator for {symbol}: {e}")
|
||||
|
||||
def _on_enhanced_cob_update(self, symbol: str, data: Dict):
|
||||
"""Handle enhanced COB updates with WebSocket status"""
|
||||
try:
|
||||
|
Reference in New Issue
Block a user