#!/usr/bin/env python3 """ 启动交易策略监控面板 """ import os import sys from pathlib import Path # 添加项目路径到Python路径 project_root = Path(__file__).parent sys.path.insert(0, str(project_root / "src")) from leadlag.web_dashboard import TradingDashboard def main(): """启动Web Dashboard""" # 数据库路径 - 优先使用测试数据库 test_db_path = project_root / "test_trading_data.db" main_db_path = project_root / "trading_data.db" # 选择存在的数据库文件 if test_db_path.exists(): db_path = test_db_path print("🧪 使用测试数据库") elif main_db_path.exists(): db_path = main_db_path print("📊 使用主数据库") else: db_path = main_db_path print("⚠️ 数据库文件不存在,将创建新数据库") print("=" * 60) print("🚀 启动交易策略监控面板") print("=" * 60) print(f"📁 数据库路径: {db_path}") print(f"🌐 访问地址: http://127.0.0.1:5000") print("=" * 60) # 检查数据库是否存在 if not db_path.exists(): print("⚠️ 警告: 数据库文件不存在,请先运行交易策略生成数据") print(f" 数据库将在策略运行时自动创建: {db_path}") print() # 创建并启动dashboard dashboard = TradingDashboard(str(db_path)) try: dashboard.run(host='127.0.0.1', port=5000, debug=False) except KeyboardInterrupt: print("\n👋 监控面板已停止") except Exception as e: print(f"❌ 启动失败: {e}") sys.exit(1) if __name__ == '__main__': main()