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
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""
|
||
Gateway 服务测试
|
||
"""
|
||
|
||
import pytest # type: ignore
|
||
from httpx import AsyncClient # type: ignore
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
class TestGatewayHealth:
|
||
"""Gateway 健康检查测试"""
|
||
|
||
async def test_ping(self, gateway_client: AsyncClient) -> None:
|
||
"""测试 ping 接口"""
|
||
response = await gateway_client.get("/ping")
|
||
assert response.status_code == 200
|
||
data = response.json()
|
||
assert data["status"] == "ok"
|
||
|
||
async def test_health(self, gateway_client: AsyncClient) -> None:
|
||
"""测试 health 接口"""
|
||
response = await gateway_client.get("/health")
|
||
assert response.status_code == 200
|
||
data = response.json()
|
||
assert data["status"] == "healthy"
|
||
assert data["service"] == "gateway"
|
||
|
||
|
||
@pytest.mark.asyncio
|
||
class TestGatewayMarket:
|
||
"""Gateway 行情接口测试"""
|
||
|
||
async def test_get_tick(self, gateway_client: AsyncClient) -> None:
|
||
"""测试获取 Tick"""
|
||
response = await gateway_client.get("/api/v1/market/tick/000001.SZ")
|
||
# 可能返回 200 或 503(服务不可用)
|
||
assert response.status_code in [200, 503]
|
||
|
||
async def test_get_kline(self, gateway_client: AsyncClient) -> None:
|
||
"""测试获取 K 线"""
|
||
response = await gateway_client.get(
|
||
"/api/v1/market/kline/000001.SZ",
|
||
params={"period": "1d", "count": 10},
|
||
)
|
||
assert response.status_code in [200, 503]
|