training wip

This commit is contained in:
Dobromir Popov
2025-07-27 23:45:57 +03:00
parent 39267697f3
commit b4076241c9
4 changed files with 283 additions and 66 deletions

View File

@ -5328,8 +5328,11 @@ class CleanTradingDashboard:
# Cold start training moved to core.training_integration.TrainingIntegration
def _clear_session(self):
"""Clear session data and persistent files"""
"""Clear session data, close all positions, and reset PnL"""
try:
# Close all held positions first
self._close_all_positions()
# Reset session metrics
self.session_pnl = 0.0
self.total_fees = 0.0
@ -5393,12 +5396,58 @@ class CleanTradingDashboard:
logger.info("✅ Session data and trade logs cleared successfully")
logger.info("📊 Session P&L reset to $0.00")
logger.info("📈 Position cleared")
logger.info("📈 All positions closed")
logger.info("📋 Trade history cleared")
except Exception as e:
logger.error(f"❌ Error clearing session: {e}")
def _close_all_positions(self):
"""Close all held positions"""
try:
# Close positions via trading executor if available
if hasattr(self, 'trading_executor') and self.trading_executor:
try:
# Close ETH/USDT position
self.trading_executor.close_position('ETH/USDT')
logger.info("🔒 Closed ETH/USDT position")
except Exception as e:
logger.warning(f"Failed to close ETH/USDT position: {e}")
try:
# Close BTC/USDT position
self.trading_executor.close_position('BTC/USDT')
logger.info("🔒 Closed BTC/USDT position")
except Exception as e:
logger.warning(f"Failed to close BTC/USDT position: {e}")
# Also try to close via orchestrator if available
if hasattr(self, 'orchestrator') and self.orchestrator:
try:
if hasattr(self.orchestrator, '_close_all_positions'):
self.orchestrator._close_all_positions()
logger.info("🔒 Closed all positions via orchestrator")
except Exception as e:
logger.warning(f"Failed to close positions via orchestrator: {e}")
# Reset position tracking
self.current_position = None
if hasattr(self, 'position_size'):
self.position_size = 0.0
if hasattr(self, 'position_entry_price'):
self.position_entry_price = None
if hasattr(self, 'position_pnl'):
self.position_pnl = 0.0
if hasattr(self, 'unrealized_pnl'):
self.unrealized_pnl = 0.0
if hasattr(self, 'realized_pnl'):
self.realized_pnl = 0.0
logger.info("✅ All positions closed and PnL reset")
except Exception as e:
logger.error(f"❌ Error closing positions: {e}")
def _clear_trade_logs(self):
"""Clear all trade log files"""
try: