i think we fixed mexc interface at the end!!!

This commit is contained in:
Dobromir Popov
2025-07-04 02:14:29 +03:00
parent 978cecf0c5
commit cf91e090c8
7 changed files with 445 additions and 613 deletions

View File

@ -1934,11 +1934,13 @@ class CleanTradingDashboard:
# Fallback if orchestrator not available or returns None
if model_states is None:
# FIXED: No longer using hardcoded placeholder loss values
# Dashboard should show "No Data" or actual training status instead
model_states = {
'dqn': {'initial_loss': 0.2850, 'current_loss': 0.0145, 'best_loss': 0.0098, 'checkpoint_loaded': False},
'cnn': {'initial_loss': 0.4120, 'current_loss': 0.0187, 'best_loss': 0.0134, 'checkpoint_loaded': False},
'cob_rl': {'initial_loss': 0.3560, 'current_loss': 0.0098, 'best_loss': 0.0076, 'checkpoint_loaded': False},
'decision': {'initial_loss': 0.2980, 'current_loss': 0.0089, 'best_loss': 0.0065, 'checkpoint_loaded': False}
'dqn': {'initial_loss': None, 'current_loss': None, 'best_loss': None, 'checkpoint_loaded': False},
'cnn': {'initial_loss': None, 'current_loss': None, 'best_loss': None, 'checkpoint_loaded': False},
'cob_rl': {'initial_loss': None, 'current_loss': None, 'best_loss': None, 'checkpoint_loaded': False},
'decision': {'initial_loss': None, 'current_loss': None, 'best_loss': None, 'checkpoint_loaded': False}
}
# Get latest predictions from all models
@ -1956,6 +1958,13 @@ class CleanTradingDashboard:
except (TypeError, ZeroDivisionError):
return default_improvement
# Helper function to format loss values
def format_loss_value(loss_value: Optional[float]) -> str:
"""Format loss value for display, showing 'No Data' for None values"""
if loss_value is None:
return "No Data"
return f"{loss_value:.4f}"
# Helper function to get timing information
def get_model_timing_info(model_name: str) -> Dict[str, Any]:
timing = {
@ -2041,12 +2050,12 @@ class CleanTradingDashboard:
},
# FIXED: Get REAL loss values from orchestrator model, not placeholders
'loss_5ma': self._get_real_model_loss('dqn'),
'initial_loss': dqn_state.get('initial_loss', 0.2850),
'initial_loss': dqn_state.get('initial_loss'), # No fallback - show None if unknown
'best_loss': self._get_real_best_loss('dqn'),
'improvement': safe_improvement_calc(
dqn_state.get('initial_loss', 0.2850),
dqn_state.get('initial_loss'),
self._get_real_model_loss('dqn'),
0.0 if not dqn_active else 94.9 # Default if no real improvement available
0.0 # No synthetic default improvement
),
'checkpoint_loaded': dqn_checkpoint_loaded,
'model_type': 'DQN',
@ -2109,13 +2118,13 @@ class CleanTradingDashboard:
'predicted_price': cnn_predicted_price,
'type': cnn_latest.get('type', 'cnn_pivot') if cnn_latest else 'cnn_pivot'
},
'loss_5ma': cnn_state.get('current_loss', 0.0187),
'initial_loss': cnn_state.get('initial_loss', 0.4120),
'best_loss': cnn_state.get('best_loss', 0.0134),
'loss_5ma': cnn_state.get('current_loss'),
'initial_loss': cnn_state.get('initial_loss'),
'best_loss': cnn_state.get('best_loss'),
'improvement': safe_improvement_calc(
cnn_state.get('initial_loss', 0.4120),
cnn_state.get('current_loss', 0.0187),
95.5 # Default improvement percentage
cnn_state.get('initial_loss'),
cnn_state.get('current_loss'),
0.0 # No synthetic default improvement
),
'checkpoint_loaded': cnn_state.get('checkpoint_loaded', False),
'model_type': 'CNN',
@ -3948,11 +3957,11 @@ class CleanTradingDashboard:
except Exception:
return default
def _get_real_model_loss(self, model_name: str) -> float:
def _get_real_model_loss(self, model_name: str) -> Optional[float]:
"""Get REAL current loss from the actual model, not placeholders"""
try:
if not self.orchestrator:
return 0.2850 # Default fallback
return None # No orchestrator = no real data
if model_name == 'dqn' and hasattr(self.orchestrator, 'rl_agent') and self.orchestrator.rl_agent:
# Get real loss from DQN agent
@ -3961,8 +3970,8 @@ class CleanTradingDashboard:
# Average of last 50 losses for current loss
recent_losses = agent.losses[-50:]
return sum(recent_losses) / len(recent_losses)
elif hasattr(agent, 'current_loss'):
return float(getattr(agent, 'current_loss', 0.2850))
elif hasattr(agent, 'current_loss') and agent.current_loss is not None:
return float(agent.current_loss)
elif model_name == 'cnn' and hasattr(self.orchestrator, 'cnn_model') and self.orchestrator.cnn_model:
# Get real loss from CNN model
@ -3970,8 +3979,8 @@ class CleanTradingDashboard:
if hasattr(model, 'training_losses') and len(getattr(model, 'training_losses',[])) > 0:
recent_losses = getattr(model, 'training_losses',[])[-50:]
return sum(recent_losses) / len(recent_losses)
elif hasattr(model, 'current_loss'):
return float(getattr(model, 'current_loss', 0.2850))
elif hasattr(model, 'current_loss') and model.current_loss is not None:
return float(model.current_loss)
elif model_name == 'decision' and hasattr(self.orchestrator, 'decision_fusion_network'):
# Get real loss from decision fusion
@ -3983,45 +3992,45 @@ class CleanTradingDashboard:
# Fallback to model states
model_states = self.orchestrator.get_model_states() if hasattr(self.orchestrator, 'get_model_states') else {}
state = model_states.get(model_name, {})
return state.get('current_loss', 0.2850)
return state.get('current_loss') # Return None if no real data
except Exception as e:
logger.debug(f"Error getting real loss for {model_name}: {e}")
return 0.2850 # Safe fallback
return None # Return None instead of synthetic data
def _get_real_best_loss(self, model_name: str) -> float:
def _get_real_best_loss(self, model_name: str) -> Optional[float]:
"""Get REAL best loss from the actual model"""
try:
if not self.orchestrator:
return 0.0145 # Default fallback
return None # No orchestrator = no real data
if model_name == 'dqn' and hasattr(self.orchestrator, 'rl_agent') and self.orchestrator.rl_agent:
agent = self.orchestrator.rl_agent
if hasattr(agent, 'best_loss'):
return float(getattr(agent, 'best_loss', 0.0145))
if hasattr(agent, 'best_loss') and agent.best_loss is not None:
return float(agent.best_loss)
elif hasattr(agent, 'losses') and len(agent.losses) > 0:
return min(agent.losses)
elif model_name == 'cnn' and hasattr(self.orchestrator, 'cnn_model') and self.orchestrator.cnn_model:
model = self.orchestrator.cnn_model
if hasattr(model, 'best_loss'):
return float(getattr(model, 'best_loss', 0.0145))
if hasattr(model, 'best_loss') and model.best_loss is not None:
return float(model.best_loss)
elif hasattr(model, 'training_losses') and len(getattr(model, 'training_losses', [])) > 0:
return min(getattr(model, 'training_losses', [0.0145]))
return min(getattr(model, 'training_losses', []))
elif model_name == 'decision' and hasattr(self.orchestrator, 'fusion_training_data'):
if len(self.orchestrator.fusion_training_data) > 0:
all_losses = [entry['loss'] for entry in self.orchestrator.fusion_training_data]
return min(all_losses) if all_losses else 0.0065
return min(all_losses) if all_losses else None
# Fallback to model states
model_states = self.orchestrator.get_model_states() if hasattr(self.orchestrator, 'get_model_states') else {}
state = model_states.get(model_name, {})
return state.get('best_loss', 0.0145)
return state.get('best_loss') # Return None if no real data
except Exception as e:
logger.debug(f"Error getting best loss for {model_name}: {e}")
return 0.0145 # Safe fallback
return None # Return None instead of synthetic data
def _clear_old_signals_for_tick_range(self):
"""Clear old signals that are outside the current tick cache time range - VERY CONSERVATIVE"""