Phase 4: Core Service (port 8010) - Pairing management (symbol-strategy pairs) - Order service with Redis pub/sub - Position and balance tracking Phase 5: Strategy Engine (port 8030) - BaseStrategy abstract class - Strategy registry and executor - Built-in strategies: Grid, MA Cross, Dual MA - Signal manager with Redis integration Phase 6: QMT Adapter (port 8040) - XtQuant SDK wrapper with simulation mode - Order executor listening to Redis channels - Quote pusher and account syncer Phase 7: Testing & Documentation - Pytest fixtures for all services - Unit tests for models and strategies - Windows startup scripts
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""
|
|
Strategy Engine 测试
|
|
"""
|
|
|
|
import pytest # type: ignore
|
|
from httpx import AsyncClient # type: ignore
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
class TestStrategyEngineHealth:
|
|
"""Strategy Engine 健康检查测试"""
|
|
|
|
async def test_ping(self, strategy_engine_client: AsyncClient) -> None:
|
|
"""测试 ping 接口"""
|
|
response = await strategy_engine_client.get("/ping")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "ok"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
class TestStrategyRegistry:
|
|
"""策略注册测试"""
|
|
|
|
async def test_list_strategies(self, strategy_engine_client: AsyncClient) -> None:
|
|
"""测试获取策略列表"""
|
|
response = await strategy_engine_client.get("/api/v1/strategy/list")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "strategies" in data
|
|
|
|
async def test_get_builtin_strategies(
|
|
self, strategy_engine_client: AsyncClient
|
|
) -> None:
|
|
"""测试获取内置策略"""
|
|
response = await strategy_engine_client.get("/api/v1/strategy/builtin")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert "strategies" in data
|
|
# 应该有内置策略
|
|
builtin = data["strategies"]
|
|
assert "grid" in builtin or "ma_cross" in builtin or "dual_ma" in builtin
|