Commit Graph

3 Commits

Author SHA1 Message Date
0f23037448 重构架构:实现单一职责原则和最小接口设计
主要修改:
1. CacheManager 负责数据库降级(单一职责)
   - 缓存未命中自动从数据库加载
   - 移除 StrategyManager/Context 的 db_manager 依赖

2. 添加 StrategyContext 核心组件
   - Position: 持仓管理
   - Capital: 资金管理
   - RiskState: 风险控制
   - BaseStrategy: 策略基类

3. 配置与类型修复
   - global.yaml 添加完整缓存配置
   - 修复 Pylance 类型推断错误
   - Config.load_with_global() 合并全局配置

4. 技术设计文档
   - 架构重构总结
   - 缓存设计方案
   - Context 共享策略
   - 接口最小化原则
2025-12-27 22:52:40 +08:00
b44f761c2b 重构通信层:分离业务逻辑和通信细节,实现策略管理器 2025-12-26 19:54:54 +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