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
- 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
- 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