核心功能: - 创建database_service (API方式管理数据库和表) - 实现BacktestEngine (简洁的回测API,支持GUI/CLI) - 回测引擎入口 (src/backtest/main.py) 服务管理优化: - HTTPService支持后台运行 (CREATE_NO_WINDOW) - 日志重定向到文件 (logs/<服务名>.log) - 统一启动流程 (显示计划、进度、结果摘要) - 优雅退出 (捕获KeyboardInterrupt) 代码结构重构: - setup_services() - 配置服务 - start_xxx() - 启动流程 - main() - 简洁主函数 - 职责分离清晰,易于维护 新增文件: - src/database_service/ - 数据库管理服务 - src/backtest/ - 回测引擎模块 - examples/backtest_gui_example.py - GUI示例 - docs/architecture/BACKTEST_ENGINE_DESIGN.md - 设计文档 配置文件: - configs/global.yaml - 添加database_service端口 - src/backtest_service/app.py - 添加/health端点
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""
|
|
测试多环境配置
|
|
|
|
验证不同环境的配置是否正确加载
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到路径
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
|
|
def test_environment(env_name: str, env_file: str):
|
|
"""测试指定环境的配置"""
|
|
print(f"\n{'=' * 60}")
|
|
print(f"测试环境: {env_name}")
|
|
print(f"{'=' * 60}")
|
|
|
|
# 设置环境变量
|
|
os.environ["CONFIG_FILE"] = f"configs/{env_file}"
|
|
|
|
# 重新导入配置(清除缓存)
|
|
if "src.core.config" in sys.modules:
|
|
del sys.modules["src.core.config"]
|
|
|
|
from src.core.config import settings
|
|
|
|
# 显示配置信息
|
|
print(f"环境名称: {settings.environment.env}")
|
|
print(f"数据库名: {settings.environment.db_name}")
|
|
print(f"Redis前缀: {settings.environment.redis_prefix}")
|
|
print(f"端口偏移: {settings.environment.port_offset}")
|
|
print()
|
|
print(f"数据库URL: {settings.database.url}")
|
|
print()
|
|
print("Redis频道:")
|
|
print(f" K线更新: {settings.channels.kline_update}")
|
|
print(f" 信号创建: {settings.channels.signal_create}")
|
|
print(f" 订单更新: {settings.channels.order_update}")
|
|
print(f" 成交更新: {settings.channels.trade_update}")
|
|
print()
|
|
print("服务端口:")
|
|
try:
|
|
print(f" DataService: {settings.services.data_service.port}")
|
|
print(f" StrategyService: {settings.services.strategy_service.port}")
|
|
except Exception:
|
|
print(" (服务端口配置可能不存在)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# 测试三个环境
|
|
test_environment("实盘环境", "production.yaml")
|
|
test_environment("回测环境", "backtest.yaml")
|
|
test_environment("模拟环境", "simulation.yaml")
|
|
|
|
print(f"\n{'=' * 60}")
|
|
print("✅ 所有环境配置测试完成")
|
|
print(f"{'=' * 60}\n")
|