trading sim agin while training

This commit is contained in:
Dobromir Popov
2025-07-15 03:04:34 +03:00
parent 0b07825be0
commit e586d850f1
2 changed files with 60 additions and 5 deletions

View File

@ -42,7 +42,7 @@ exchanges:
bybit:
enabled: true
test_mode: false # Use mainnet (your credentials are for live trading)
trading_mode: "live" # simulation, testnet, live
trading_mode: "simulation" # simulation, testnet, live - SWITCHED TO SIMULATION FOR TRAINING
supported_symbols: ["BTCUSDT", "ETHUSDT"] # Bybit perpetual format
base_position_percent: 5.0
max_position_percent: 20.0

View File

@ -107,6 +107,11 @@ class CleanTradingDashboard:
else:
self.orchestrator = orchestrator
# Connect trading executor to orchestrator for signal execution
if hasattr(self.orchestrator, 'set_trading_executor'):
self.orchestrator.set_trading_executor(self.trading_executor)
logger.info("Trading executor connected to orchestrator for signal execution")
# Initialize enhanced training system for predictions
self.training_system = None
self._initialize_enhanced_training_system()
@ -211,6 +216,10 @@ class CleanTradingDashboard:
# Start signal generation loop to ensure continuous trading signals
self._start_signal_generation_loop()
# Start order status monitoring for live mode
if not self.trading_executor.simulation_mode:
threading.Thread(target=self._monitor_order_execution, daemon=True).start()
# Start training sessions if models are showing FRESH status
threading.Thread(target=self._delayed_training_check, daemon=True).start()
@ -230,6 +239,43 @@ class CleanTradingDashboard:
logger.error(f"Error getting universal data from orchestrator: {e}")
return None
def _monitor_order_execution(self):
"""Monitor order execution status in live mode and update dashboard signals"""
try:
logger.info("Starting order execution monitoring for live mode")
while True:
time.sleep(5) # Check every 5 seconds
# Check for signals that were attempted but not yet executed
for decision in self.recent_decisions:
if (decision.get('execution_attempted', False) and
not decision.get('executed', False) and
not decision.get('execution_failure', False)):
# Check if the order was actually filled
symbol = decision.get('symbol', 'ETH/USDT')
action = decision.get('action', 'HOLD')
# Check if position was actually opened/closed
if self.trading_executor and hasattr(self.trading_executor, 'positions'):
if symbol in self.trading_executor.positions:
position = self.trading_executor.positions[symbol]
if ((action == 'BUY' and position.side == 'LONG') or
(action == 'SELL' and position.side == 'SHORT')):
# Order was actually filled
decision['executed'] = True
decision['execution_confirmed_time'] = datetime.now()
logger.info(f"ORDER EXECUTION CONFIRMED: {action} for {symbol}")
else:
# Position exists but doesn't match expected action
logger.debug(f"Position exists but doesn't match action: {action} vs {position.side}")
else:
# No position exists, order might still be pending
logger.debug(f"No position found for {symbol}, order may still be pending")
except Exception as e:
logger.error(f"Error in order execution monitoring: {e}")
def _delayed_training_check(self):
"""Check and start training after a delay to allow initialization"""
try:
@ -5790,7 +5836,7 @@ class CleanTradingDashboard:
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
if self.trading_executor: # Execute every signal
try:
logger.info(f"[ORCHESTRATOR EXECUTION] Attempting to execute {action} for {symbol} via trading executor...")
success = self.trading_executor.execute_signal(
@ -5801,9 +5847,18 @@ class CleanTradingDashboard:
)
if success:
dashboard_decision['executed'] = True
dashboard_decision['execution_time'] = datetime.now()
logger.info(f"[ORCHESTRATOR EXECUTION] SUCCESS: {action} executed for {symbol}")
# In live mode, only mark as executed if order was actually filled
if self.trading_executor.simulation_mode:
# Simulation mode: mark as executed immediately
dashboard_decision['executed'] = True
dashboard_decision['execution_time'] = datetime.now()
logger.info(f"[ORCHESTRATOR EXECUTION] SUCCESS: {action} executed for {symbol} (SIMULATION)")
else:
# Live mode: mark as attempted, will be updated when order fills
dashboard_decision['executed'] = False
dashboard_decision['execution_attempted'] = True
dashboard_decision['execution_time'] = datetime.now()
logger.info(f"[ORCHESTRATOR EXECUTION] ATTEMPTED: {action} order placed for {symbol} (LIVE)")
# Sync position from trading executor after execution
self._sync_position_from_executor(symbol)