wip
This commit is contained in:
@ -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'
|
||||
|
Reference in New Issue
Block a user