manual close btn

This commit is contained in:
Dobromir Popov
2025-08-08 11:47:51 +03:00
parent 6214bc2e9f
commit c58ec789f2
5 changed files with 48 additions and 25 deletions

View File

@ -1536,6 +1536,37 @@ class CleanTradingDashboard:
self._execute_manual_trade('SELL')
return [html.I(className="fas fa-arrow-down me-1"), "SELL"]
@self.app.callback(
Output('manual-close-btn', 'children'),
[Input('manual-close-btn', 'n_clicks')],
prevent_initial_call=True
)
def handle_manual_close(n_clicks):
"""Handle manual close/exit button: closes any active position for the primary symbol"""
if not n_clicks:
raise PreventUpdate
symbol = getattr(self, 'primary_symbol', 'ETH/USDT')
try:
# If executor tracks positions, close whichever side is active
if hasattr(self.trading_executor, 'positions') and symbol in self.trading_executor.positions:
position = self.trading_executor.positions[symbol]
if getattr(position, 'side', 'LONG') == 'LONG':
# Close long by selling
if hasattr(self.trading_executor, 'close_long_position'):
self.trading_executor.close_long_position(symbol, confidence=1.0)
elif hasattr(self.trading_executor, 'sell'):
self.trading_executor.sell(symbol, quantity=position.quantity, confidence=1.0)
else:
# Close short by buying
if hasattr(self.trading_executor, 'close_short_position'):
self.trading_executor.close_short_position(symbol, confidence=1.0)
elif hasattr(self.trading_executor, 'buy'):
self.trading_executor.buy(symbol, quantity=position.quantity, confidence=1.0)
return [html.I(className="fas fa-times me-1"), "CLOSE"]
except Exception as e:
logger.error(f"Error closing position manually: {e}")
return [html.I(className="fas fa-times me-1"), "CLOSE"]
# Leverage slider callback
@self.app.callback(
Output('leverage-display', 'children'),
@ -7261,28 +7292,14 @@ class CleanTradingDashboard:
def _initialize_enhanced_training_system(self):
"""Initialize enhanced training system for model predictions"""
try:
# Try to import and initialize enhanced training system
from enhanced_realtime_training import EnhancedRealtimeTrainingSystem # Optional
self.training_system = EnhancedRealtimeTrainingSystem(
orchestrator=self.orchestrator,
data_provider=self.data_provider,
dashboard=self
)
# Initialize prediction storage
if not hasattr(self.orchestrator, 'recent_dqn_predictions'):
self.orchestrator.recent_dqn_predictions = {}
if not hasattr(self.orchestrator, 'recent_cnn_predictions'):
self.orchestrator.recent_cnn_predictions = {}
logger.debug("Enhanced training system initialized for model predictions")
# Optional module is not required; skip and rely on orchestrator built-in training
self.training_system = None
return
except ImportError:
logger.warning("Enhanced training system not available - predictions disabled for this module")
logger.info("Enhanced training system not available - using built-in training only")
self.training_system = None
except Exception as e:
logger.error(f"Error initializing enhanced training system: {e}")
logger.info(f"Enhanced training system skipped: {e}")
self.training_system = None
def _initialize_standardized_cnn(self):

View File

@ -344,7 +344,12 @@ class DashboardLayoutManager:
html.Button([
html.I(className="fas fa-arrow-down me-1"),
"SELL"
], id="manual-sell-btn", className="btn btn-danger btn-sm",
], id="manual-sell-btn", className="btn btn-danger btn-sm me-2",
style={"fontSize": "10px", "padding": "2px 8px"}),
html.Button([
html.I(className="fas fa-times me-1"),
"CLOSE"
], id="manual-close-btn", className="btn btn-secondary btn-sm",
style={"fontSize": "10px", "padding": "2px 8px"})
], className="d-flex")
], className="d-flex justify-content-between align-items-center mb-2"),