run_dashboard.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python3
  2. """
  3. 启动交易策略监控面板
  4. """
  5. import os
  6. import sys
  7. from pathlib import Path
  8. # 添加项目路径到Python路径
  9. project_root = Path(__file__).parent
  10. sys.path.insert(0, str(project_root / "src"))
  11. from leadlag.web_dashboard import TradingDashboard
  12. def main():
  13. """启动Web Dashboard"""
  14. # 数据库路径 - 优先使用测试数据库
  15. test_db_path = project_root / "test_trading_data.db"
  16. main_db_path = project_root / "trading_data.db"
  17. # 选择存在的数据库文件
  18. if test_db_path.exists():
  19. db_path = test_db_path
  20. print("🧪 使用测试数据库")
  21. elif main_db_path.exists():
  22. db_path = main_db_path
  23. print("📊 使用主数据库")
  24. else:
  25. db_path = main_db_path
  26. print("⚠️ 数据库文件不存在,将创建新数据库")
  27. print("=" * 60)
  28. print("🚀 启动交易策略监控面板")
  29. print("=" * 60)
  30. print(f"📁 数据库路径: {db_path}")
  31. print(f"🌐 访问地址: http://127.0.0.1:5000")
  32. print("=" * 60)
  33. # 检查数据库是否存在
  34. if not db_path.exists():
  35. print("⚠️ 警告: 数据库文件不存在,请先运行交易策略生成数据")
  36. print(f" 数据库将在策略运行时自动创建: {db_path}")
  37. print()
  38. # 创建并启动dashboard
  39. dashboard = TradingDashboard(str(db_path))
  40. try:
  41. dashboard.run(host='127.0.0.1', port=5000, debug=False)
  42. except KeyboardInterrupt:
  43. print("\n👋 监控面板已停止")
  44. except Exception as e:
  45. print(f"❌ 启动失败: {e}")
  46. sys.exit(1)
  47. if __name__ == '__main__':
  48. main()