fix dash actions
This commit is contained in:
@ -4850,17 +4850,19 @@ class CleanTradingDashboard:
|
||||
logger.error(f"Error initiating orchestrator connection: {e}")
|
||||
|
||||
async def _on_trading_decision(self, decision):
|
||||
"""Handle trading decision from orchestrator."""
|
||||
"""Handle trading decision from orchestrator and execute through trading executor."""
|
||||
try:
|
||||
# Handle both object and dict formats
|
||||
if hasattr(decision, 'action'):
|
||||
action = getattr(decision, 'action', 'HOLD')
|
||||
symbol = getattr(decision, 'symbol', 'ETH/USDT')
|
||||
confidence = getattr(decision, 'confidence', 0.0)
|
||||
price = getattr(decision, 'price', None)
|
||||
else:
|
||||
action = decision.get('action', 'HOLD')
|
||||
symbol = decision.get('symbol', 'ETH/USDT')
|
||||
confidence = decision.get('confidence', 0.0)
|
||||
price = decision.get('price', None)
|
||||
|
||||
if action == 'HOLD':
|
||||
return
|
||||
@ -4886,11 +4888,45 @@ class CleanTradingDashboard:
|
||||
dashboard_decision['timestamp'] = datetime.now()
|
||||
dashboard_decision['executed'] = False
|
||||
|
||||
logger.info(f"[ORCHESTRATOR SIGNAL] Received: {action} for {symbol} (confidence: {confidence:.3f})")
|
||||
|
||||
# EXECUTE THE DECISION THROUGH TRADING EXECUTOR
|
||||
if self.trading_executor and confidence > 0.5: # Only execute high confidence signals
|
||||
try:
|
||||
logger.info(f"[ORCHESTRATOR EXECUTION] Attempting to execute {action} for {symbol} via trading executor...")
|
||||
success = self.trading_executor.execute_signal(
|
||||
symbol=symbol,
|
||||
action=action,
|
||||
confidence=confidence,
|
||||
current_price=price
|
||||
)
|
||||
|
||||
if success:
|
||||
dashboard_decision['executed'] = True
|
||||
dashboard_decision['execution_time'] = datetime.now()
|
||||
logger.info(f"[ORCHESTRATOR EXECUTION] SUCCESS: {action} executed for {symbol}")
|
||||
|
||||
# Sync position from trading executor after execution
|
||||
self._sync_position_from_executor(symbol)
|
||||
|
||||
else:
|
||||
logger.warning(f"[ORCHESTRATOR EXECUTION] FAILED: {action} execution blocked for {symbol}")
|
||||
dashboard_decision['execution_failure'] = True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[ORCHESTRATOR EXECUTION] ERROR: Failed to execute {action} for {symbol}: {e}")
|
||||
dashboard_decision['execution_error'] = str(e)
|
||||
else:
|
||||
if not self.trading_executor:
|
||||
logger.warning("[ORCHESTRATOR EXECUTION] No trading executor available")
|
||||
elif confidence <= 0.5:
|
||||
logger.info(f"[ORCHESTRATOR EXECUTION] Low confidence signal ignored: {action} for {symbol} (confidence: {confidence:.3f})")
|
||||
|
||||
# Store decision in dashboard
|
||||
self.recent_decisions.append(dashboard_decision)
|
||||
if len(self.recent_decisions) > 200:
|
||||
self.recent_decisions.pop(0)
|
||||
|
||||
logger.info(f"[ORCHESTRATOR SIGNAL] Received: {action} for {symbol} (confidence: {confidence:.3f})")
|
||||
except Exception as e:
|
||||
logger.error(f"Error handling trading decision: {e}")
|
||||
|
||||
|
Reference in New Issue
Block a user