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
hidden_size: 256 # Hidden layer size
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
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:

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