#!/usr/bin/env python3 """ Clean Main Entry Point for Enhanced Trading Dashboard This is the main entry point that safely launches the clean dashboard with proper error handling and optimized settings. """ import os import sys import logging import argparse from typing import Optional # Add project root to path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # Import core components try: from core.config import setup_logging from core.data_provider import DataProvider from core.orchestrator import TradingOrchestrator from core.trading_executor import TradingExecutor from web.clean_dashboard import create_clean_dashboard except ImportError as e: print(f"Error importing core modules: {e}") sys.exit(1) logger = logging.getLogger(__name__) def create_safe_orchestrator() -> Optional[TradingOrchestrator]: """Create orchestrator with safe CNN model handling""" try: # Create orchestrator with basic configuration (uses correct constructor parameters) orchestrator = TradingOrchestrator( enhanced_rl_training=False # Disable problematic training initially ) logger.info("Trading orchestrator created successfully") return orchestrator except Exception as e: logger.error(f"Error creating orchestrator: {e}") logger.info("Continuing without orchestrator - dashboard will run in view-only mode") return None def create_safe_trading_executor() -> Optional[TradingExecutor]: """Create trading executor with safe configuration""" try: # TradingExecutor only accepts config_path parameter trading_executor = TradingExecutor(config_path="config.yaml") logger.info("Trading executor created successfully") return trading_executor except Exception as e: logger.error(f"Error creating trading executor: {e}") logger.info("Continuing without trading executor - dashboard will be view-only") return None def main(): """Main entry point for clean dashboard""" parser = argparse.ArgumentParser(description='Enhanced Trading Dashboard') parser.add_argument('--port', type=int, default=8050, help='Dashboard port (default: 8050)') parser.add_argument('--host', type=str, default='127.0.0.1', help='Dashboard host (default: 127.0.0.1)') parser.add_argument('--debug', action='store_true', help='Enable debug mode') parser.add_argument('--no-training', action='store_true', help='Disable ML training for stability') args = parser.parse_args() # Setup logging try: setup_logging() logger.info("================================================================================") logger.info("CLEAN ENHANCED TRADING DASHBOARD") logger.info("================================================================================") logger.info(f"Starting on http://{args.host}:{args.port}") logger.info("Features: Real-time Charts, Trading Interface, Model Monitoring") logger.info("================================================================================") except Exception as e: print(f"Error setting up logging: {e}") # Continue without logging setup # Set environment variables for optimization os.environ['ENABLE_REALTIME_CHARTS'] = '1' if not args.no_training: os.environ['ENABLE_NN_MODELS'] = '1' try: # Create data provider logger.info("Initializing data provider...") data_provider = DataProvider(symbols=['ETH/USDT', 'BTC/USDT']) # Create orchestrator (with safe CNN handling) logger.info("Initializing trading orchestrator...") orchestrator = create_safe_orchestrator() # Create trading executor logger.info("Initializing trading executor...") trading_executor = create_safe_trading_executor() # Create and run dashboard logger.info("Creating clean dashboard...") dashboard = create_clean_dashboard( data_provider=data_provider, orchestrator=orchestrator, trading_executor=trading_executor ) # Start the dashboard server logger.info(f"Starting dashboard server on http://{args.host}:{args.port}") dashboard.run_server( host=args.host, port=args.port, debug=args.debug ) except KeyboardInterrupt: logger.info("Dashboard stopped by user") except Exception as e: logger.error(f"Error running dashboard: {e}") # Try to provide helpful error message if "model.fit" in str(e) or "CNN" in str(e): logger.error("CNN model training error detected. Try running with --no-training flag") logger.error("Command: python main_clean.py --no-training") sys.exit(1) finally: logger.info("Clean dashboard shutdown complete") if __name__ == '__main__': main()