wip UI clear session
This commit is contained in:
@ -5321,14 +5321,46 @@ class CleanTradingDashboard:
|
||||
self.closed_trades = []
|
||||
self.recent_decisions = []
|
||||
|
||||
# Clear all trade-related data
|
||||
if hasattr(self, 'trades'):
|
||||
self.trades = []
|
||||
if hasattr(self, 'session_trades'):
|
||||
self.session_trades = []
|
||||
if hasattr(self, 'trade_history'):
|
||||
self.trade_history = []
|
||||
if hasattr(self, 'open_trades'):
|
||||
self.open_trades = []
|
||||
|
||||
# Clear position data
|
||||
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
|
||||
|
||||
# Clear tick cache and associated signals
|
||||
self.tick_cache = []
|
||||
self.ws_price_cache = {}
|
||||
self.current_prices = {}
|
||||
|
||||
# Clear current position and pending trade tracking
|
||||
self.current_position = None
|
||||
self.pending_trade_case_id = None # Clear pending trade tracking
|
||||
# Clear pending trade tracking
|
||||
self.pending_trade_case_id = None
|
||||
if hasattr(self, 'pending_trades'):
|
||||
self.pending_trades = []
|
||||
|
||||
# Reset session timing
|
||||
if hasattr(self, 'session_start_time'):
|
||||
self.session_start_time = datetime.now()
|
||||
|
||||
# Clear any cached dashboard data
|
||||
if hasattr(self, 'dashboard_cache'):
|
||||
self.dashboard_cache = {}
|
||||
|
||||
# Clear persistent trade log files
|
||||
self._clear_trade_logs()
|
||||
@ -5337,10 +5369,20 @@ class CleanTradingDashboard:
|
||||
if hasattr(self, 'orchestrator') and self.orchestrator:
|
||||
self._clear_orchestrator_state()
|
||||
|
||||
logger.info("Session data and trade logs cleared")
|
||||
# Clear any trading executor state
|
||||
if hasattr(self, 'trading_executor') and self.trading_executor:
|
||||
self._clear_trading_executor_state()
|
||||
|
||||
# Force refresh of dashboard components
|
||||
self._force_dashboard_refresh()
|
||||
|
||||
logger.info("✅ Session data and trade logs cleared successfully")
|
||||
logger.info("📊 Session P&L reset to $0.00")
|
||||
logger.info("📈 Position cleared")
|
||||
logger.info("📋 Trade history cleared")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing session: {e}")
|
||||
logger.error(f"❌ Error clearing session: {e}")
|
||||
|
||||
def _clear_trade_logs(self):
|
||||
"""Clear all trade log files"""
|
||||
@ -5400,26 +5442,76 @@ class CleanTradingDashboard:
|
||||
def _clear_orchestrator_state(self):
|
||||
"""Clear orchestrator state and recent predictions"""
|
||||
try:
|
||||
if hasattr(self.orchestrator, 'recent_decisions'):
|
||||
self.orchestrator.recent_decisions = {}
|
||||
|
||||
if hasattr(self.orchestrator, 'recent_dqn_predictions'):
|
||||
for symbol in self.orchestrator.recent_dqn_predictions:
|
||||
self.orchestrator.recent_dqn_predictions[symbol].clear()
|
||||
|
||||
if hasattr(self.orchestrator, 'recent_cnn_predictions'):
|
||||
for symbol in self.orchestrator.recent_cnn_predictions:
|
||||
self.orchestrator.recent_cnn_predictions[symbol].clear()
|
||||
|
||||
if hasattr(self.orchestrator, 'prediction_accuracy_history'):
|
||||
for symbol in self.orchestrator.prediction_accuracy_history:
|
||||
self.orchestrator.prediction_accuracy_history[symbol].clear()
|
||||
|
||||
logger.info("Orchestrator state cleared")
|
||||
# Use the orchestrator's built-in clear method if available
|
||||
if hasattr(self.orchestrator, 'clear_session_data'):
|
||||
self.orchestrator.clear_session_data()
|
||||
else:
|
||||
# Fallback to manual clearing
|
||||
if hasattr(self.orchestrator, 'recent_decisions'):
|
||||
self.orchestrator.recent_decisions = {}
|
||||
|
||||
if hasattr(self.orchestrator, 'recent_dqn_predictions'):
|
||||
for symbol in self.orchestrator.recent_dqn_predictions:
|
||||
self.orchestrator.recent_dqn_predictions[symbol].clear()
|
||||
|
||||
if hasattr(self.orchestrator, 'recent_cnn_predictions'):
|
||||
for symbol in self.orchestrator.recent_cnn_predictions:
|
||||
self.orchestrator.recent_cnn_predictions[symbol].clear()
|
||||
|
||||
if hasattr(self.orchestrator, 'prediction_accuracy_history'):
|
||||
for symbol in self.orchestrator.prediction_accuracy_history:
|
||||
self.orchestrator.prediction_accuracy_history[symbol].clear()
|
||||
|
||||
logger.info("Orchestrator state cleared (fallback method)")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing orchestrator state: {e}")
|
||||
|
||||
def _clear_trading_executor_state(self):
|
||||
"""Clear trading executor state and positions"""
|
||||
try:
|
||||
if hasattr(self.trading_executor, 'current_positions'):
|
||||
self.trading_executor.current_positions = {}
|
||||
|
||||
if hasattr(self.trading_executor, 'trade_history'):
|
||||
self.trading_executor.trade_history = []
|
||||
|
||||
if hasattr(self.trading_executor, 'session_pnl'):
|
||||
self.trading_executor.session_pnl = 0.0
|
||||
|
||||
if hasattr(self.trading_executor, 'total_fees'):
|
||||
self.trading_executor.total_fees = 0.0
|
||||
|
||||
if hasattr(self.trading_executor, 'open_orders'):
|
||||
self.trading_executor.open_orders = {}
|
||||
|
||||
logger.info("Trading executor state cleared")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing trading executor state: {e}")
|
||||
|
||||
def _force_dashboard_refresh(self):
|
||||
"""Force refresh of dashboard components after clearing session"""
|
||||
try:
|
||||
# Reset any cached data that might prevent updates
|
||||
if hasattr(self, '_last_update_time'):
|
||||
self._last_update_time = {}
|
||||
|
||||
if hasattr(self, '_cached_data'):
|
||||
self._cached_data = {}
|
||||
|
||||
# Clear any component-specific caches
|
||||
if hasattr(self, '_chart_cache'):
|
||||
self._chart_cache = {}
|
||||
|
||||
if hasattr(self, '_stats_cache'):
|
||||
self._stats_cache = {}
|
||||
|
||||
logger.info("Dashboard refresh triggered after session clear")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error forcing dashboard refresh: {e}")
|
||||
|
||||
def _store_all_models(self) -> bool:
|
||||
"""Store all current models to persistent storage"""
|
||||
try:
|
||||
|
Reference in New Issue
Block a user