better clean dash
This commit is contained in:
@ -101,13 +101,16 @@ class CleanTradingDashboard:
|
||||
# Start data streams
|
||||
self._initialize_streaming()
|
||||
|
||||
# Connect to orchestrator for real trading signals
|
||||
self._connect_to_orchestrator()
|
||||
|
||||
logger.info("Clean Trading Dashboard initialized")
|
||||
|
||||
def _get_initial_balance(self) -> float:
|
||||
"""Get initial balance from trading executor or default"""
|
||||
try:
|
||||
if self.trading_executor and hasattr(self.trading_executor, 'get_balance'):
|
||||
balance = self.trading_executor.get_balance()
|
||||
if self.trading_executor and hasattr(self.trading_executor, 'starting_balance'):
|
||||
balance = getattr(self.trading_executor, 'starting_balance', None)
|
||||
if balance and balance > 0:
|
||||
return balance
|
||||
except Exception as e:
|
||||
@ -632,6 +635,42 @@ class CleanTradingDashboard:
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing session: {e}")
|
||||
|
||||
def _connect_to_orchestrator(self):
|
||||
"""Connect to orchestrator for real trading signals"""
|
||||
try:
|
||||
if self.orchestrator and hasattr(self.orchestrator, 'add_decision_callback'):
|
||||
# Register callback to receive trading decisions
|
||||
self.orchestrator.add_decision_callback(self._on_trading_decision)
|
||||
logger.info("Connected to orchestrator for trading signals")
|
||||
else:
|
||||
logger.warning("Orchestrator not available or doesn't support callbacks")
|
||||
except Exception as e:
|
||||
logger.error(f"Error connecting to orchestrator: {e}")
|
||||
|
||||
def _on_trading_decision(self, decision):
|
||||
"""Handle trading decision from orchestrator"""
|
||||
try:
|
||||
# Convert orchestrator decision to dashboard format
|
||||
dashboard_decision = {
|
||||
'timestamp': datetime.now().strftime('%H:%M:%S'),
|
||||
'action': decision.action if hasattr(decision, 'action') else decision.get('action', 'UNKNOWN'),
|
||||
'confidence': decision.confidence if hasattr(decision, 'confidence') else decision.get('confidence', 0),
|
||||
'price': decision.price if hasattr(decision, 'price') else decision.get('price', 0),
|
||||
'executed': True, # Orchestrator decisions are executed
|
||||
'blocked': False,
|
||||
'manual': False
|
||||
}
|
||||
|
||||
# Add to recent decisions
|
||||
self.recent_decisions.append(dashboard_decision)
|
||||
|
||||
# Keep only last 50 decisions
|
||||
if len(self.recent_decisions) > 50:
|
||||
self.recent_decisions = self.recent_decisions[-50:]
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling trading decision: {e}")
|
||||
|
||||
def _initialize_streaming(self):
|
||||
"""Initialize data streaming"""
|
||||
try:
|
||||
|
Reference in New Issue
Block a user