gogo2/main_clean.py
2025-05-30 22:33:41 +03:00

167 lines
6.6 KiB
Python

#!/usr/bin/env python3
"""
Streamlined Trading System - Web Dashboard Only
Simplified entry point with only the web dashboard mode:
- Streamlined Flow: Data -> Indicators/Pivots -> CNN -> RL -> Orchestrator -> Execution
- 2-Action System: BUY/SELL with intelligent position management
- Always invested approach with smart risk/reward setup detection
Usage:
python main_clean.py [--symbol ETH/USDT] [--port 8050]
"""
import asyncio
import argparse
import logging
import sys
from pathlib import Path
from threading import Thread
import time
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from core.config import get_config, setup_logging, Config
from core.data_provider import DataProvider
logger = logging.getLogger(__name__)
def run_web_dashboard():
"""Run the streamlined web dashboard with 2-action system and always-invested approach"""
try:
logger.info("Starting Streamlined Trading Dashboard...")
logger.info("2-Action System: BUY/SELL with intelligent position management")
logger.info("Always Invested Approach: Smart risk/reward setup detection")
logger.info("Integrated Training Pipeline: Live data -> Models -> Trading")
# Get configuration
config = get_config()
# Initialize core components for streamlined pipeline
from core.data_provider import DataProvider
from core.enhanced_orchestrator import EnhancedTradingOrchestrator
from core.trading_executor import TradingExecutor
# Create data provider
data_provider = DataProvider()
# Verify data connection
logger.info("[DATA] Verifying live data connection...")
symbol = config.get('symbols', ['ETH/USDT'])[0]
test_df = data_provider.get_historical_data(symbol, '1m', limit=10)
if test_df is not None and len(test_df) > 0:
logger.info("[SUCCESS] Data connection verified")
logger.info(f"[SUCCESS] Fetched {len(test_df)} candles for validation")
else:
logger.error("[ERROR] Data connection failed - no live data available")
return
# Load model registry for integrated pipeline
try:
from core.model_registry import get_model_registry
model_registry = get_model_registry()
logger.info("[MODELS] Model registry loaded for integrated training")
except ImportError:
model_registry = {}
logger.warning("Model registry not available, using empty registry")
# Create streamlined orchestrator with 2-action system and always-invested approach
orchestrator = EnhancedTradingOrchestrator(
data_provider=data_provider,
symbols=config.get('symbols', ['ETH/USDT']),
enhanced_rl_training=True,
model_registry=model_registry
)
logger.info("Enhanced Trading Orchestrator with 2-Action System initialized")
logger.info("Always Invested: Learning to spot high risk/reward setups")
# Create trading executor for live execution
trading_executor = TradingExecutor()
# Import and create streamlined dashboard
from web.dashboard import TradingDashboard
dashboard = TradingDashboard(
data_provider=data_provider,
orchestrator=orchestrator,
trading_executor=trading_executor
)
# Start the integrated dashboard
port = config.get('web', {}).get('port', 8050)
host = config.get('web', {}).get('host', '127.0.0.1')
logger.info(f"Starting Streamlined Dashboard at http://{host}:{port}")
logger.info("Live Data Processing: ENABLED")
logger.info("Integrated CNN Training: ENABLED")
logger.info("Integrated RL Training: ENABLED")
logger.info("Real-time Indicators & Pivots: ENABLED")
logger.info("Live Trading Execution: ENABLED")
logger.info("2-Action System: BUY/SELL with position intelligence")
logger.info("Always Invested: Different thresholds for entry/exit")
logger.info("Pipeline: Data -> Indicators -> CNN -> RL -> Orchestrator -> Execution")
dashboard.run(host=host, port=port, debug=False)
except Exception as e:
logger.error(f"Error in streamlined dashboard: {e}")
logger.error("Dashboard stopped - trying minimal fallback")
try:
# Minimal fallback dashboard
from web.dashboard import TradingDashboard
from core.data_provider import DataProvider
data_provider = DataProvider()
dashboard = TradingDashboard(data_provider)
logger.info("Using minimal fallback dashboard")
dashboard.run(host='127.0.0.1', port=8050, debug=False)
except Exception as fallback_error:
logger.error(f"Fallback dashboard failed: {fallback_error}")
logger.error(f"Fatal error: {e}")
import traceback
logger.error(traceback.format_exc())
async def main():
"""Main entry point with streamlined web-only operation"""
parser = argparse.ArgumentParser(description='Streamlined Trading System - 2-Action Web Dashboard')
parser.add_argument('--symbol', type=str, default='ETH/USDT',
help='Primary trading symbol (default: ETH/USDT)')
parser.add_argument('--port', type=int, default=8050,
help='Web dashboard port (default: 8050)')
parser.add_argument('--debug', action='store_true',
help='Enable debug mode')
args = parser.parse_args()
# Setup logging
setup_logging()
try:
logger.info("=" * 70)
logger.info("STREAMLINED TRADING SYSTEM - 2-ACTION WEB DASHBOARD")
logger.info(f"Primary Symbol: {args.symbol}")
logger.info(f"Web Port: {args.port}")
logger.info("2-Action System: BUY/SELL with intelligent position management")
logger.info("Always Invested: Learning to spot high risk/reward setups")
logger.info("Flow: Data -> Indicators -> CNN -> RL -> Orchestrator -> Execution")
logger.info("=" * 70)
# Run the web dashboard
run_web_dashboard()
logger.info("[SUCCESS] Operation completed successfully!")
except KeyboardInterrupt:
logger.info("System shutdown requested by user")
except Exception as e:
logger.error(f"Fatal error: {e}")
import traceback
logger.error(traceback.format_exc())
return 1
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))