fix model mappings,dash updates, trading

This commit is contained in:
Dobromir Popov
2025-07-22 15:44:59 +03:00
parent 3e35b9cddb
commit 1a54fb1d56
32 changed files with 6168 additions and 857 deletions

View File

@ -948,9 +948,11 @@ class TradingOrchestrator:
for model_name in self.model_weights:
self.model_weights[model_name] /= total_weight
def add_decision_callback(self, callback):
async def add_decision_callback(self, callback):
"""Add a callback function to be called when decisions are made"""
self.decision_callbacks.append(callback)
logger.info(f"Decision callback registered: {callback.__name__ if hasattr(callback, '__name__') else 'unnamed'}")
return True
async def make_trading_decision(self, symbol: str) -> Optional[TradingDecision]:
"""
@ -1844,23 +1846,52 @@ class TradingOrchestrator:
logger.error(f"Error setting training dashboard: {e}")
def get_universal_data_stream(self, current_time: Optional[datetime] = None):
"""Get universal data stream for external consumers like dashboard"""
"""Get universal data stream for external consumers like dashboard - DELEGATED to data provider"""
try:
return self.universal_adapter.get_universal_data_stream(current_time)
if self.data_provider and hasattr(self.data_provider, 'universal_adapter'):
return self.data_provider.universal_adapter.get_universal_data_stream(current_time)
elif self.universal_adapter:
return self.universal_adapter.get_universal_data_stream(current_time)
return None
except Exception as e:
logger.error(f"Error getting universal data stream: {e}")
return None
def get_universal_data_for_model(self, model_type: str = 'cnn') -> Optional[Dict[str, Any]]:
"""Get formatted universal data for specific model types"""
"""Get formatted universal data for specific model types - DELEGATED to data provider"""
try:
stream = self.universal_adapter.get_universal_data_stream()
if stream:
return self.universal_adapter.format_for_model(stream, model_type)
if self.data_provider and hasattr(self.data_provider, 'universal_adapter'):
stream = self.data_provider.universal_adapter.get_universal_data_stream()
if stream:
return self.data_provider.universal_adapter.format_for_model(stream, model_type)
elif self.universal_adapter:
stream = self.universal_adapter.get_universal_data_stream()
if stream:
return self.universal_adapter.format_for_model(stream, model_type)
return None
except Exception as e:
logger.error(f"Error getting universal data for {model_type}: {e}")
return None
def get_cob_data(self, symbol: str) -> Optional[Dict[str, Any]]:
"""Get COB data for symbol - DELEGATED to data provider"""
try:
if self.data_provider:
return self.data_provider.get_latest_cob_data(symbol)
return None
except Exception as e:
logger.error(f"Error getting COB data for {symbol}: {e}")
return None
def get_combined_model_data(self, symbol: str) -> Optional[Dict[str, Any]]:
"""Get combined OHLCV + COB data for models - DELEGATED to data provider"""
try:
if self.data_provider:
return self.data_provider.get_combined_ohlcv_cob_data(symbol)
return None
except Exception as e:
logger.error(f"Error getting combined model data for {symbol}: {e}")
return None
def _get_current_position_pnl(self, symbol: str, current_price: float) -> float:
"""Get current position P&L for the symbol"""
@ -2120,7 +2151,7 @@ class TradingOrchestrator:
# Create state representation
state = self._create_state_for_training(symbol, market_data)
# Map action to DQN action space
# Map action to DQN action space - CONSISTENT ACTION MAPPING
action_mapping = {'BUY': 0, 'SELL': 1, 'HOLD': 2}
dqn_action = action_mapping.get(action, 2)