xtquant-proxy 提供了一个通用的 RESTful 接口,使迅投 QMT 可以跨平台使用,方便在 Windows Server 上启动 miniQMT,在 Linux Server 上进行量化处理。
xtquant-proxy 提供了一个通用的 RESTful 接口,使迅投 QMT 可以跨平台使用,方便在 Windows Server 上启动 miniQMT,在 Linux Server 上进行量化处理。
开发状态:
v0.0.1迭代中 | 当前已支持 gRPC / REST / WebSocket、多环境mock / dev / prod和本地xtquant代理能力;后续将继续补充更多 xtquant 能力、真实联调体验和客户端示例
xtquant / QMT,同时提供 gRPC、REST 和 WebSocket 三种接入方式mock / dev / prod 三环境切换,便于本地开发、模拟账号联调和真实环境接入已通过 miniQMT模拟客户端 全量用例,真实环境全量功能待验证
3.10 - 3.13mock 模式不需要 QMTdev / prod 模式需要本机已登录可用的 MiniQMT / QMTpython -m venv .venv
.venv\Scripts\activate.bat
pip install -r requirements.txt
pip install pytest pytest-asyncio如果 python 命令不可用,可以改用:
py -3.13 -m venv .venv
.venv\Scripts\activate.bat
pip install -r requirements.txt
pip install pytest pytest-asyncioset APP_MODE=mock
set APP_SERVERS=all
python run.py也可以使用启动脚本:
python start.py --mode mock --servers allhttp://localhost:8000http://localhost:8000/docshttp://localhost:8000/redoclocalhost:50051python -m pytest tests\\unit -q --xt-mode=mock配置文件按用途分为三类:
config.yml:仓库默认配置config.local.yml:本机运行时覆盖配置config.test.local.yml:本机真实环境测试覆盖配置通常建议:
mock:直接通过环境变量启动dev / prod 运行:使用 config.local.ymldev / prod pytest:使用 config.test.local.ymlconfig.yml 不预置本机 QMT 路径,请在本地覆盖配置中填写本地 mock 不需要额外配置文件:
set APP_MODE=mock
set APP_SERVERS=all
python run.py只启动 REST / WebSocket:
set APP_MODE=mock
set APP_SERVERS=rest
python run.py只启动 gRPC:
set APP_MODE=mock
set APP_SERVERS=grpc
python run.py先复制运行时本地配置:
copy config.local.example.yml config.local.yml示例:
xtquant:
qmt_userdata_path: "C:\\path\\to\\your\\QMT\\\userdata"
trading:
enable_prod_orders: false
accounts:
- name: "sim-dev"
account_id: "你的模拟账号"
account_type: "STOCK"
account_kind: "simulated"
allowed_modes: ["dev"]
enabled: true
- name: "prod-main"
account_id: "你的真实账号"
account_type: "STOCK"
account_kind: "real"
allowed_modes: ["prod"]
enabled: true说明:
qmt_userdata_path 要填 QMT 的用户数据目录,不是安装根目录userdata_miniuserdatadev 只能使用 simulated 账号prod 只能使用 real 账号prod 下真实下单,需要显式开启 xtquant.trading.enable_prod_orders: true启动示例:
set APP_MODE=dev
set APP_SERVERS=all
python run.pyset APP_MODE=prod
set APP_SERVERS=all
python run.py如果要跑真实 xtquant 测试,再复制测试专用配置:
copy config.test.local.example.yml config.test.local.yml这个文件主要用于:
testing.default_account_profiletesting.enable_prod_readonly_teststesting.prod_unlock_tokentesting.qmt_userdata_pathxtquant.trading.accounts| 模式 | xtquant | 账号要求 | 自动化下单 |
|---|---|---|---|
mock |
不连接 | 无 | 本地假实现 |
dev |
真实 xtquant | 显式登记的 simulated 账号 |
允许 |
prod |
真实 xtquant | 显式登记的 real 账号 |
测试用例中只读 |
说明:
mock 适合本地开发和默认测试dev 适合模拟账号联调,走真实 xtquant 接口prod 自动化测试默认只读,用于验证真实账号查询、订阅和拒单行为prod 自动化只读只约束测试用例;真实部署后,外部模块是否能下单仍由 xtquant.trading.enable_prod_orders 控制同时支持三种服务装配方式:
APP_SERVERS=all:同时启动 REST 和 gRPCAPP_SERVERS=rest:只启动 REST / WebSocketAPP_SERVERS=grpc:只启动 gRPC数据接口:
POST /api/v1/data/kline-historyPOST /api/v1/data/tick-historyPOST /api/v1/data/full-tickPOST /api/v1/data/financialGET /api/v1/data/instrument/{symbol}POST /api/v1/data/trading-calendarPOST /api/v1/data/index-weightGET /api/v1/data/sectorsPOST /api/v1/data/l2/quotePOST /api/v1/data/l2/orderPOST /api/v1/data/l2/transactionPOST /api/v1/data/subscriptions/quotePOST /api/v1/data/subscriptions/whole-quoteGET /api/v1/data/subscriptionsGET /api/v1/data/subscriptions/{subscription_id}DELETE /api/v1/data/subscriptions/{subscription_id}交易接口:
POST /api/v1/trading/sessionsGET /api/v1/trading/sessions/{session_id}DELETE /api/v1/trading/sessions/{session_id}GET /api/v1/trading/sessions/{session_id}/assetGET /api/v1/trading/sessions/{session_id}/positionsGET /api/v1/trading/sessions/{session_id}/ordersGET /api/v1/trading/sessions/{session_id}/tradesPOST /api/v1/trading/sessions/{session_id}/ordersPOST /api/v1/trading/sessions/{session_id}/cancel健康接口:
GET /GET /health/GET /health/readyGET /health/live数据服务:
GetKlineHistoryGetTickHistoryGetFullTickSnapshotGetFinancialDataGetInstrumentDetailGetTradingCalendarGetIndexWeightGetSectorListGetL2QuoteGetL2OrderGetL2TransactionStreamQuoteStreamWholeQuote交易服务:
OpenSessionCloseSessionGetSessionGetStockAssetGetStockPositionsGetStockOrdersGetStockTradesSubmitStockOrderCancelStockOrderStreamTradingEventsGET /ws/quote/{subscription_id}默认测试只跑本地 mock:
python -m pytest tests\\unit -q --xt-mode=mock按模块运行:
python -m pytest tests\\unit\test_rest_api_interfaces.py -q --xt-mode=mock
python -m pytest tests\\unit\test_rest_websocket.py -q --xt-mode=mock
python -m pytest tests\\unit\test_grpc_api_interfaces.py -q --xt-mode=mock
python -m pytest tests\\unit\test_health_and_auth.py -q --xt-mode=mock
python -m pytest tests\\unit\test_trading_service.py -q --xt-mode=mockpython -m pytest tests\\unit -q --xt-mode=dev --xt-account-profile=sim-dev --xt-enable-live-streamsset QMT_TEST_PROD_UNLOCK_TOKEN=your-token
python -m pytest tests\\unit -q --xt-mode=prod --xt-account-profile=prod-main --xt-enable-prod-tests说明:
prod pytest 只验证查询、订阅、鉴权和拒单prod pytest 不会真实下单 / 撤单prod 放单请通过你自己的外部模块或手工联调验证quant-qmt-proxy/
├── app/ # 应用代码
├── proto/ # protobuf 定义
├── generated/ # protobuf 生成代码
├── tests/ # 测试
├── xtquant/ # 本地 xtquant SDK
├── scripts/ # 辅助脚本
├── config.yml # 默认配置
├── config.local.example.yml
├── config.test.local.example.yml
├── run.py # 启动入口
└── start.py # 启动脚本涉及 xtquant / QMT 的接口签名、生命周期、返回结构和调用方式时,以两类来源为准:
欢迎提交 Issue 和 Pull Request。
如果修改了 proto/*.proto,请同步执行:
python scripts\generate_proto.py --mode generateMIT License,详见 LICENSE。
暂无开放 Issues,或尚未同步最近议题。