From d4d3c755143649d63c83aa42e206fdbeba45ae37 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Wed, 25 Jun 2025 03:42:00 +0300 Subject: [PATCH] use enhanced orchestrator --- _dev/notes.md | 10 ++++- core/realtime_rl_cob_trader.py | 1 - core/shared_cob_service.py | 1 - training/williams_market_structure.py | 4 -- utils/reward_calculator.py | 1 - web/clean_dashboard.py | 53 +++++++++++++++++++++++++-- web/cob_realtime_dashboard.py | 2 - 7 files changed, 58 insertions(+), 14 deletions(-) diff --git a/_dev/notes.md b/_dev/notes.md index f7f66ac..7ab7180 100644 --- a/_dev/notes.md +++ b/_dev/notes.md @@ -33,6 +33,11 @@ how effective is our training? show current loss and accuracy on the chart. also what are our rewards and penalties in the RL training pipeline? reprt them so we can evaluate them and make sure they are working as expected and do improvements +allow models to be dynamically loaded and unloaded from the webui (orchestrator) + +show cob data in the dashboard over ws + +report and audit rewards and penalties in the RL training pipeline >> clean dashboard @@ -68,4 +73,7 @@ use existing checkpoint manager if it;s not too bloated as well. otherwise re-im - [ ] Chart updates every second - [ ] No flickering or data loss - [ ] WebSocket connection stable -- [ ] Memory usage reasonable \ No newline at end of file +- [ ] Memory usage reasonable + + + diff --git a/core/realtime_rl_cob_trader.py b/core/realtime_rl_cob_trader.py index 8ddf89d..9ae0eaf 100644 --- a/core/realtime_rl_cob_trader.py +++ b/core/realtime_rl_cob_trader.py @@ -93,7 +93,6 @@ class TradeSignal: # MassiveRLNetwork is now imported from NN.models.cob_rl_model - class RealtimeRLCOBTrader: """ Real-time RL trader using COB data with comprehensive subscriber system diff --git a/core/shared_cob_service.py b/core/shared_cob_service.py index 15ed1fc..c11aae5 100644 --- a/core/shared_cob_service.py +++ b/core/shared_cob_service.py @@ -332,7 +332,6 @@ class SharedCOBService: return base_stats - # Global service instance access functions def get_shared_cob_service(symbols: List[str] = None, data_provider: DataProvider = None) -> SharedCOBService: diff --git a/training/williams_market_structure.py b/training/williams_market_structure.py index da65666..dd96739 100644 --- a/training/williams_market_structure.py +++ b/training/williams_market_structure.py @@ -36,7 +36,6 @@ from typing import Dict, List, Optional, Tuple, Any from dataclasses import dataclass from enum import Enum - # Setup logger immediately after logging import logger = logging.getLogger(__name__) @@ -167,7 +166,6 @@ except ImportError: TrainingDataPacket = None print("Warning: TrainingDataPacket could not be imported. Using fallback interface.") - class TrendDirection(Enum): UP = "up" DOWN = "down" @@ -964,7 +962,6 @@ class WilliamsMarketStructure: else: y_train_batch = y_train - logger.info(f"CNN Training with X_shape: {X_train_batch.shape}, y_shape: {y_train_batch.shape}") # Perform a single step of training (online learning) # Use the wrapper's fit method, not the model's directly @@ -1340,7 +1337,6 @@ class WilliamsMarketStructure: # Emergency fallback: return features as-is but scaled to [0,1] roughly return np.clip(features / (np.max(np.abs(features)) + 1e-8), -1.0, 1.0) - def _get_cnn_ground_truth(self, previous_pivot_info: Dict[str, Any], # Contains 'pivot': SwingPoint obj of N-1 actual_current_pivot: SwingPoint # This is pivot N diff --git a/utils/reward_calculator.py b/utils/reward_calculator.py index 76fab56..d0c2b9a 100644 --- a/utils/reward_calculator.py +++ b/utils/reward_calculator.py @@ -194,7 +194,6 @@ class ImprovedRewardCalculator: return reward - # Example usage: if __name__ == "__main__": # Create calculator instance diff --git a/web/clean_dashboard.py b/web/clean_dashboard.py index cd548b0..95f5a66 100644 --- a/web/clean_dashboard.py +++ b/web/clean_dashboard.py @@ -31,7 +31,7 @@ logger = logging.getLogger(__name__) # Import core components from core.config import get_config from core.data_provider import DataProvider -from core.orchestrator import TradingOrchestrator +from core.enhanced_orchestrator import EnhancedTradingOrchestrator from core.trading_executor import TradingExecutor # Import layout and component managers @@ -60,13 +60,22 @@ from core.realtime_rl_cob_trader import RealtimeRLCOBTrader, PredictionResult class CleanTradingDashboard: """Clean, modular trading dashboard implementation""" - def __init__(self, data_provider: DataProvider = None, orchestrator: TradingOrchestrator = None, trading_executor: TradingExecutor = None): + def __init__(self, data_provider: DataProvider = None, orchestrator: EnhancedTradingOrchestrator = None, trading_executor: TradingExecutor = None): self.config = get_config() # Initialize components self.data_provider = data_provider or DataProvider() - self.orchestrator = orchestrator - self.trading_executor = trading_executor + self.trading_executor = trading_executor or TradingExecutor() + + # Initialize orchestrator with enhanced capabilities + if orchestrator is None: + self.orchestrator = EnhancedTradingOrchestrator( + data_provider=self.data_provider, + symbols=['ETH/USDT', 'BTC/USDT'], + enhanced_rl_training=True + ) + else: + self.orchestrator = orchestrator # Initialize layout and component managers self.layout_manager = DashboardLayoutManager( @@ -126,6 +135,42 @@ class CleanTradingDashboard: logger.info("Clean Trading Dashboard initialized with COB RL integration") + def load_model_dynamically(self, model_name: str, model_type: str, model_path: str = None) -> bool: + """Dynamically load a model at runtime""" + try: + if hasattr(self.orchestrator, 'load_model'): + success = self.orchestrator.load_model(model_name, model_type, model_path) + if success: + logger.info(f"Successfully loaded model: {model_name}") + return True + return False + except Exception as e: + logger.error(f"Error loading model {model_name}: {e}") + return False + + def unload_model_dynamically(self, model_name: str) -> bool: + """Dynamically unload a model at runtime""" + try: + if hasattr(self.orchestrator, 'unload_model'): + success = self.orchestrator.unload_model(model_name) + if success: + logger.info(f"Successfully unloaded model: {model_name}") + return True + return False + except Exception as e: + logger.error(f"Error unloading model {model_name}: {e}") + return False + + def get_loaded_models_status(self) -> Dict[str, Any]: + """Get status of all loaded models""" + try: + if hasattr(self.orchestrator, 'list_loaded_models'): + return self.orchestrator.list_loaded_models() + return {'loaded_models': {}, 'total_models': 0, 'system_status': 'NO_ORCHESTRATOR'} + except Exception as e: + logger.error(f"Error getting model status: {e}") + return {'loaded_models': {}, 'total_models': 0, 'system_status': 'ERROR'} + def _get_initial_balance(self) -> float: """Get initial balance from trading executor or default""" try: diff --git a/web/cob_realtime_dashboard.py b/web/cob_realtime_dashboard.py index ae67d9e..58c8fc5 100644 --- a/web/cob_realtime_dashboard.py +++ b/web/cob_realtime_dashboard.py @@ -537,7 +537,6 @@ class COBDashboardServer: logger.error(f"Error in cleanup: {e}") await asyncio.sleep(300) - async def main(): """Main entry point""" # Set up logging @@ -565,6 +564,5 @@ async def main(): if 'server' in locals(): await server.stop() - if __name__ == "__main__": asyncio.run(main()) \ No newline at end of file