Commit Graph

6 Commits

Author SHA1 Message Date
37a5df8bf6 重构配置系统:改为Config/Logger单例模式,拆分环境配置文件
主要改动:
1. Config类改为单例模式,支持根据global.yaml的current_mode自动加载环境配置
2. Logger类改为单例模式,通过类方法直接访问
3. 拆分配置文件:global.yaml仅指定模式,backtest.yaml/simulation.yaml/production.yaml存储各环境配置
4. 移除所有config参数传递,使用Config.get()直接访问
5. 移除所有logger实例传递,使用Logger.info()等类方法直接访问
6. 修复初始化顺序:Config.initialize() -> Logger.initialize() -> 其他组件
7. 修复Logger参数默认值,确保所有方法可正常调用
8. 新增三个环境配置文件结构统一,只有参数值不同
9. 客户端URL端口修正为8030(回测)/8020(模拟)/8010(实盘)

配置文件变更:
- configs/global.yaml:简化为仅包含current_mode
- configs/backtest.yaml:回测环境完整配置
- configs/simulation.yaml:模拟环境完整配置
- configs/production.yaml:实盘环境完整配置

代码重构:
- src/core/config.py:单例模式,自动加载环境配置
- src/core/logger.py:单例模式,类方法访问
- 所有模块:移除config/logger参数,使用单例访问
2026-01-12 19:07:23 +08:00
14caec147b Major refactor: Separate business logic from communication layer
Created strategy_service module with complete architecture:
- ConfigLoader: Load and validate strategy configurations
- StrategyManager: Manage all strategy instances
- PositionManager: Track positions and capital for each instance
- RiskManager: Multi-level risk control (global/instance/signal)
- TradeRecorder: Record all signals and trades
- StrategyExecutor: Core coordinator for strategy execution

Key features:
- One symbol can have multiple independent strategy instances
- Each instance has isolated capital and positions
- No signal aggregation - each instance returns independent signals
- Multi-level risk management
- Configuration-driven strategy deployment
- Clean separation: ws_server (communication) vs strategy_service (business)

Files added:
- src/strategy_service/*.py (6 core modules)
- config/strategy_config.yaml (example configuration)
- src/networks/server/ws_server_refactored.py (new server)
- docs/backend_refactor.md (architecture documentation)

Protocol changes:
- Response now returns multiple signals (TRADE_SIGNALS)
- Each signal includes instance_id for tracking
- Added TRADE_RESULT message for trade feedback
2025-12-26 18:14:56 +08:00
61feb5daa0 Add batch kline sending method and fix type hints
- Added send_klines_batch() method in BacktestClientAdapter for sending multiple symbols' klines in one request
- Updated imports to include Dict and List types
- Fixed Pylance type checking warning in xtquant_downloader.py (added type: ignore for xtdc.close())
- Updated bt_engine.py for compatibility with new adapter methods
2025-12-26 17:49:13 +08:00
67b85ab232 Refactor: Implement WebSocket architecture with separated communication and business logic layers
- Implemented WebSocket protocol v1.0 specification with protocol headers, versioning, and batch support
- Renamed qtrade_server.py -> ws_server.py, client_adapter.py -> ws_client.py to reflect WebSocket implementation
- Created pure communication layer (WSClient) with only connect/send/close functionality
- Created business logic layer (BacktestClientAdapter) for protocol construction and signal parsing
- Updated bt_engine.py to use BacktestClientAdapter for strategy communication
- Fixed datetime formatting issues (time.strftime -> datetime.now().strftime for %f support)
- Fixed WebSocket 1000 OK close code logging issue
- Translated all logger output from Chinese to English for better compatibility
- Successfully tested with 242 K-lines data transmission

Architecture changes:
- networks/ layer: Pure WebSocket communication (no business logic)
- backtest/ layer: Business logic (protocol v1.0 message construction)
- Clear separation of concerns between transport and application layers
2025-12-25 16:15:56 +08:00
5734bf1fd0 feat: 实现XtQuant数据下载器和核心对象系统
- 新增核心对象模型(Tick, Kline, Order, Trade, Position, Account, Signal, Symbol)
- 使用Pydantic BaseModel实现自动验证
- 创建DatabaseManager管理数据库和表结构
- 实现BaseDataDownloader抽象基类
- 实现XtQuantDownloader下载历史K线数据
- 添加Config和Logger工具类
- 清理旧的微服务架构代码
- 更新配置文件为简化版本(去除Redis)
- 所有测试通过
2025-12-15 20:00:47 +08:00
099e193c2e feat: 完成回测引擎架构和服务管理优化
核心功能:
- 创建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端点
2025-12-13 10:30:31 +08:00