integrationg COB
This commit is contained in:
@ -237,8 +237,18 @@ class TradingDashboard:
|
||||
|
||||
self.data_provider = data_provider or DataProvider()
|
||||
|
||||
# Enhanced orchestrator support - FORCE ENABLE for learning
|
||||
self.orchestrator = orchestrator or TradingOrchestrator(self.data_provider)
|
||||
# Use enhanced orchestrator for comprehensive RL training
|
||||
if orchestrator is None:
|
||||
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
|
||||
self.orchestrator = EnhancedTradingOrchestrator(
|
||||
data_provider=self.data_provider,
|
||||
symbols=['ETH/USDT', 'BTC/USDT'],
|
||||
enhanced_rl_training=True
|
||||
)
|
||||
logger.info("Using Enhanced Trading Orchestrator for comprehensive RL training")
|
||||
else:
|
||||
self.orchestrator = orchestrator
|
||||
logger.info(f"Using provided orchestrator: {type(orchestrator).__name__}")
|
||||
self.enhanced_rl_enabled = True # Force enable Enhanced RL
|
||||
logger.info("Enhanced RL training FORCED ENABLED for learning")
|
||||
|
||||
@ -5036,6 +5046,16 @@ class TradingDashboard:
|
||||
logger.warning(f"Error calculating Williams pivot points: {e}")
|
||||
state_features.extend([0.0] * 250) # Default features
|
||||
|
||||
# Try to use comprehensive RL state builder first
|
||||
symbol = training_episode.get('symbol', 'ETH/USDT')
|
||||
comprehensive_state = self._build_comprehensive_rl_state(symbol)
|
||||
|
||||
if comprehensive_state is not None:
|
||||
logger.info(f"[RL_STATE] Using comprehensive state builder: {len(comprehensive_state)} features")
|
||||
return comprehensive_state
|
||||
else:
|
||||
logger.warning("[RL_STATE] Comprehensive state builder failed, using basic features")
|
||||
|
||||
# Add multi-timeframe OHLCV features (200 features: ETH 1s/1m/1d + BTC 1s)
|
||||
try:
|
||||
multi_tf_features = self._get_multi_timeframe_features(training_episode.get('symbol', 'ETH/USDT'))
|
||||
@ -5094,7 +5114,7 @@ class TradingDashboard:
|
||||
|
||||
# Prepare training data package
|
||||
training_data = {
|
||||
'state': state.tolist() if state is not None else [],
|
||||
'state': (state.tolist() if hasattr(state, 'tolist') else list(state)) if state is not None else [],
|
||||
'action': action,
|
||||
'reward': reward,
|
||||
'trade_info': {
|
||||
@ -5916,6 +5936,48 @@ class TradingDashboard:
|
||||
# Return original data as fallback
|
||||
return df_1s
|
||||
|
||||
def _build_comprehensive_rl_state(self, symbol: str) -> Optional[np.ndarray]:
|
||||
"""Build comprehensive RL state using enhanced orchestrator"""
|
||||
try:
|
||||
# Use enhanced orchestrator's comprehensive state builder
|
||||
if hasattr(self, 'orchestrator') and self.orchestrator and hasattr(self.orchestrator, 'build_comprehensive_rl_state'):
|
||||
comprehensive_state = self.orchestrator.build_comprehensive_rl_state(symbol)
|
||||
|
||||
if comprehensive_state is not None:
|
||||
logger.info(f"[ENHANCED_RL] Using comprehensive state for {symbol}: {len(comprehensive_state)} features")
|
||||
return comprehensive_state
|
||||
else:
|
||||
logger.warning(f"[ENHANCED_RL] Comprehensive state builder returned None for {symbol}")
|
||||
else:
|
||||
logger.warning("[ENHANCED_RL] Enhanced orchestrator not available")
|
||||
|
||||
# Fallback to basic state building
|
||||
logger.warning("[ENHANCED_RL] No comprehensive training data available, falling back to basic training")
|
||||
return self._build_basic_rl_state(symbol)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error building comprehensive RL state for {symbol}: {e}")
|
||||
return self._build_basic_rl_state(symbol)
|
||||
|
||||
def _build_basic_rl_state(self, symbol: str) -> Optional[np.ndarray]:
|
||||
"""Build basic RL state as fallback (original implementation)"""
|
||||
try:
|
||||
# Get multi-timeframe features (basic implementation)
|
||||
features = self._get_multi_timeframe_features(symbol)
|
||||
|
||||
if features is None:
|
||||
return None
|
||||
|
||||
# Convert to numpy array
|
||||
state_vector = np.array(features, dtype=np.float32)
|
||||
|
||||
logger.debug(f"[BASIC_RL] Built basic state for {symbol}: {len(state_vector)} features")
|
||||
return state_vector
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error building basic RL state for {symbol}: {e}")
|
||||
return None
|
||||
|
||||
def create_dashboard(data_provider: DataProvider = None, orchestrator: TradingOrchestrator = None, trading_executor: TradingExecutor = None) -> TradingDashboard:
|
||||
"""Factory function to create a trading dashboard"""
|
||||
return TradingDashboard(data_provider=data_provider, orchestrator=orchestrator, trading_executor=trading_executor)
|
Reference in New Issue
Block a user