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
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
"""
|
|
Pytest 配置和共享 fixtures
|
|
"""
|
|
|
|
import asyncio
|
|
from typing import AsyncIterator, Generator
|
|
|
|
import pytest # type: ignore
|
|
import pytest_asyncio # type: ignore
|
|
from httpx import AsyncClient, ASGITransport # type: ignore
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
|
|
"""创建事件循环"""
|
|
loop = asyncio.new_event_loop()
|
|
yield loop
|
|
loop.close()
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def gateway_client() -> AsyncIterator[AsyncClient]:
|
|
"""Gateway 测试客户端"""
|
|
from src.gateway.app import app
|
|
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def core_service_client() -> AsyncIterator[AsyncClient]:
|
|
"""Core Service 测试客户端"""
|
|
from src.core_service.app import app
|
|
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def data_service_client() -> AsyncIterator[AsyncClient]:
|
|
"""Data Service 测试客户端"""
|
|
from src.data_service.app import app
|
|
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def strategy_engine_client() -> AsyncIterator[AsyncClient]:
|
|
"""Strategy Engine 测试客户端"""
|
|
from src.strategy_engine.app import app
|
|
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def qmt_adapter_client() -> AsyncIterator[AsyncClient]:
|
|
"""QMT Adapter 测试客户端"""
|
|
from src.qmt_adapter.app import app
|
|
|
|
transport = ASGITransport(app=app)
|
|
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
yield client
|