This commit is contained in:
Dobromir Popov
2025-07-28 22:09:15 +03:00
parent bc4b72c6de
commit a341fade80
4 changed files with 4329 additions and 2395 deletions

View File

@ -167,10 +167,10 @@ orchestrator:
input_size: 128 # Size of input features for decision fusion network input_size: 128 # Size of input features for decision fusion network
hidden_size: 256 # Hidden layer size hidden_size: 256 # Hidden layer size
history_length: 20 # Number of recent decisions to include history_length: 20 # Number of recent decisions to include
training_interval: 100 # Train decision fusion every N decisions training_interval: 10 # Train decision fusion every 10 decisions in programmatic mode
learning_rate: 0.001 # Learning rate for decision fusion network learning_rate: 0.001 # Learning rate for decision fusion network
batch_size: 32 # Training batch size batch_size: 32 # Training batch size
min_samples_for_training: 50 # Minimum samples before training starts min_samples_for_training: 20 # Lower threshold for faster training in programmatic mode
# Training Configuration # Training Configuration
training: training:

File diff suppressed because it is too large Load Diff

View File

@ -2599,6 +2599,17 @@ class TradingExecutor:
logger.error(f"Error getting current position: {e}") logger.error(f"Error getting current position: {e}")
return None return None
def get_position(self, symbol: str) -> Optional[Dict[str, Any]]:
"""Get position for a symbol (alias for get_current_position for compatibility)
Args:
symbol: Trading symbol to get position for
Returns:
dict: Position information with 'side' key or None if no position
"""
return self.get_current_position(symbol)
def get_leverage(self) -> float: def get_leverage(self) -> float:
"""Get current leverage setting""" """Get current leverage setting"""
return self.mexc_config.get('leverage', 50.0) return self.mexc_config.get('leverage', 50.0)

View File

@ -1245,94 +1245,94 @@ class CleanTradingDashboard:
return [html.I(className="fas fa-exclamation-triangle me-1"), "Store Failed"] return [html.I(className="fas fa-exclamation-triangle me-1"), "Store Failed"]
return [html.I(className="fas fa-save me-1"), "Store All Models"] return [html.I(className="fas fa-save me-1"), "Store All Models"]
# Trading Mode Toggle - TEMPORARILY DISABLED TO FIX UI ERROR # Trading Mode Toggle
# @self.app.callback( @self.app.callback(
# Output('trading-mode-display', 'children'), Output('trading-mode-display', 'children'),
# Output('trading-mode-display', 'className'), Output('trading-mode-display', 'className'),
# [Input('trading-mode-switch', 'value')] [Input('trading-mode-switch', 'value')]
# ) )
# def update_trading_mode(switch_value): def update_trading_mode(switch_value):
# """Update trading mode display and apply changes""" """Update trading mode display and apply changes"""
# logger.debug(f"Trading mode callback triggered with value: {switch_value}") logger.debug(f"Trading mode callback triggered with value: {switch_value}")
# try: try:
# is_live = 'live' in (switch_value or []) is_live = 'live' in (switch_value or [])
# self.trading_mode_live = is_live self.trading_mode_live = is_live
#
# # Update trading executor mode if available # Update trading executor mode if available
# if hasattr(self, 'trading_executor') and self.trading_executor: if hasattr(self, 'trading_executor') and self.trading_executor:
# if hasattr(self.trading_executor, 'set_trading_mode'): if hasattr(self.trading_executor, 'set_trading_mode'):
# # Use the new set_trading_mode method # Use the new set_trading_mode method
# success = self.trading_executor.set_trading_mode('live' if is_live else 'simulation') success = self.trading_executor.set_trading_mode('live' if is_live else 'simulation')
# if success: if success:
# logger.info(f"TRADING MODE: {'LIVE' if is_live else 'SIMULATION'} - Mode updated successfully") logger.info(f"TRADING MODE: {'LIVE' if is_live else 'SIMULATION'} - Mode updated successfully")
# else: else:
# logger.error(f"Failed to update trading mode to {'LIVE' if is_live else 'SIMULATION'}") logger.error(f"Failed to update trading mode to {'LIVE' if is_live else 'SIMULATION'}")
# else: else:
# # Fallback to direct property setting # Fallback to direct property setting
# if is_live: if is_live:
# self.trading_executor.trading_mode = 'live' self.trading_executor.trading_mode = 'live'
# self.trading_executor.simulation_mode = False self.trading_executor.simulation_mode = False
# logger.info("TRADING MODE: LIVE - Real orders will be executed!") logger.info("TRADING MODE: LIVE - Real orders will be executed!")
# else: else:
# self.trading_executor.trading_mode = 'simulation' self.trading_executor.trading_mode = 'simulation'
# self.trading_executor.simulation_mode = True self.trading_executor.simulation_mode = True
# logger.info("TRADING MODE: SIMULATION - Orders are simulated") logger.info("TRADING MODE: SIMULATION - Orders are simulated")
#
# # Return display text and styling # Return display text and styling
# if is_live: if is_live:
# return "LIVE", "fw-bold text-danger" return "LIVE", "fw-bold text-danger"
# else: else:
# return "SIM", "fw-bold text-warning" return "SIM", "fw-bold text-warning"
#
# except Exception as e: except Exception as e:
# logger.error(f"Error updating trading mode: {e}") logger.error(f"Error updating trading mode: {e}")
# return "ERROR", "fw-bold text-danger" return "ERROR", "fw-bold text-danger"
# Cold Start Toggle - TEMPORARILY DISABLED TO FIX UI ERROR # Cold Start Toggle
# @self.app.callback( @self.app.callback(
# Output('cold-start-display', 'children'), Output('cold-start-display', 'children'),
# Output('cold-start-display', 'className'), Output('cold-start-display', 'className'),
# [Input('cold-start-switch', 'value')] [Input('cold-start-switch', 'value')]
# ) )
# def update_cold_start(switch_value): def update_cold_start(switch_value):
# """Update cold start training mode""" """Update cold start training mode"""
# logger.debug(f"Cold start callback triggered with value: {switch_value}") logger.debug(f"Cold start callback triggered with value: {switch_value}")
# try: try:
# is_enabled = 'enabled' in (switch_value or []) is_enabled = 'enabled' in (switch_value or [])
# self.cold_start_enabled = is_enabled self.cold_start_enabled = is_enabled
#
# # Update orchestrator cold start mode if available # Update orchestrator cold start mode if available
# if hasattr(self, 'orchestrator') and self.orchestrator: if hasattr(self, 'orchestrator') and self.orchestrator:
# if hasattr(self.orchestrator, 'set_cold_start_training_enabled'): if hasattr(self.orchestrator, 'set_cold_start_training_enabled'):
# # Use the new set_cold_start_training_enabled method # Use the new set_cold_start_training_enabled method
# success = self.orchestrator.set_cold_start_training_enabled(is_enabled) success = self.orchestrator.set_cold_start_training_enabled(is_enabled)
# if success: if success:
# logger.info(f"COLD START: {'ON' if is_enabled else 'OFF'} - Training mode updated successfully") logger.info(f"COLD START: {'ON' if is_enabled else 'OFF'} - Training mode updated successfully")
# else: else:
# logger.error(f"Failed to update cold start training to {'ON' if is_enabled else 'OFF'}") logger.error(f"Failed to update cold start training to {'ON' if is_enabled else 'OFF'}")
# else: else:
# # Fallback to direct property setting # Fallback to direct property setting
# if hasattr(self.orchestrator, 'cold_start_enabled'): if hasattr(self.orchestrator, 'cold_start_enabled'):
# self.orchestrator.cold_start_enabled = is_enabled self.orchestrator.cold_start_enabled = is_enabled
#
# # Update training frequency based on cold start mode # Update training frequency based on cold start mode
# if hasattr(self.orchestrator, 'training_frequency'): if hasattr(self.orchestrator, 'training_frequency'):
# if is_enabled: if is_enabled:
# self.orchestrator.training_frequency = 'high' # Train on every signal self.orchestrator.training_frequency = 'high' # Train on every signal
# logger.info("COLD START: ON - Excessive training enabled") logger.info("COLD START: ON - Excessive training enabled")
# else: else:
# self.orchestrator.training_frequency = 'normal' # Normal training self.orchestrator.training_frequency = 'normal' # Normal training
# logger.info("COLD START: OFF - Normal training frequency") logger.info("COLD START: OFF - Normal training frequency")
#
# # Return display text and styling # Return display text and styling
# if is_enabled: if is_enabled:
# return "ON", "fw-bold text-success" return "ON", "fw-bold text-success"
# else: else:
# return "OFF", "fw-bold text-secondary" return "OFF", "fw-bold text-secondary"
#
# except Exception as e: except Exception as e:
# logger.error(f"Error updating cold start mode: {e}") logger.error(f"Error updating cold start mode: {e}")
# return "ERROR", "fw-bold text-danger" return "ERROR", "fw-bold text-danger"
def _get_leverage_applied_by_exchange(self) -> bool: def _get_leverage_applied_by_exchange(self) -> bool:
"""Check if leverage is already applied by the exchange""" """Check if leverage is already applied by the exchange"""
@ -7952,13 +7952,20 @@ class CleanTradingDashboard:
current_position = self.trading_executor.get_position(symbol) current_position = self.trading_executor.get_position(symbol)
# check if we are already in a position for this symbol # check if we are already in a position for this symbol
if current_position: if current_position:
if current_position['side'] == 'BUY' and action == 'SELL': # Handle both 'BUY'/'SELL' and 'LONG'/'SHORT' formats
position_side = current_position['side'].upper()
if position_side in ['BUY', 'LONG']:
position_side = 'BUY'
elif position_side in ['SELL', 'SHORT']:
position_side = 'SELL'
if position_side == 'BUY' and action == 'SELL':
direction = 'EXIT' direction = 'EXIT'
elif current_position['side'] == 'SELL' and action == 'BUY': elif position_side == 'SELL' and action == 'BUY':
direction = 'EXIT' direction = 'EXIT'
elif current_position['side'] == 'BUY' and action == 'BUY': elif position_side == 'BUY' and action == 'BUY':
direction = 'HOLD' direction = 'HOLD'
elif current_position['side'] == 'SELL' and action == 'SELL': elif position_side == 'SELL' and action == 'SELL':
direction = 'HOLD' direction = 'HOLD'
else: else:
direction = 'ENTER' direction = 'ENTER'