qmt-bridge-trading
通过 QMT Bridge HTTP API 执行证券交易:持仓/资产/委托查询、单笔与批量下单、撤单、清仓。 在用户提到 qmt-bridge 交易、下单、持仓、清仓、撤单、查询资产,或需操作 miniQMT 账户时使用。 本文件随 QMT Trading Skill(qmt-trading-skill…
от atorber★ 27 звёзд на GitHub
Установить qmt-bridge-trading в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
QMT Trading Skill · 交易
发布位置:
qmt-trading-skill仓库skills/qmt-bridge-trading/SKILL.md。集成说明见skills/README.md、路线图 与文档 agent-skills.md。相关 Skill:复盘 execution-review、风控 portfolio-risk、撤单 order-ops。
通过已部署的 QMT Bridge 服务(FastAPI + miniQMT)完成真实交易操作。服务端须在 Windows 上运行,并启用交易模块。
可执行脚本(优先使用)
在仓库根目录执行(需 pip install -e .,环境变量见 .env)。优先调用脚本,避免在对话中手写长 curl/Python;脚本只输出摘要,不 dump 全量 JSON。
| 脚本 | 作用 | 示例 |
|---|---|---|
scripts/trading_status.py |
只读:health + 账户状态 + 持仓/资产摘要 | python skills/qmt-bridge-trading/scripts/trading_status.py |
scripts/place_order.py |
单笔下单(默认预览) | .../place_order.py 000001.SZ --buy --volume 100 --execute --confirm |
scripts/liquidate.py |
清仓计划/执行(默认预览) | .../liquidate.py → 确认后 .../liquidate.py --execute --confirm |
路径均相对于本 skill 目录:skills/qmt-bridge-trading/scripts/。
实盘提交须同时带 --execute --confirm(place_order / liquidate)。交易前先跑 trading_status.py。
前置检查(每次交易前)
- 服务可用:
GET /api/meta/health(无需 Key) - 交易已启用:启动参数含
--trading或QMT_BRIDGE_TRADING_ENABLED=true - 认证:所有
/api/trading/*请求头携带X-API-Key: <密钥>(与服务端QMT_BRIDGE_API_KEY一致) - 账户:多账户时传
account_id;留空则使用服务端默认户(QMT_BRIDGE_DEFAULT_ACCOUNT指定 stock/credit) - 连接:下单前建议
GET /api/trading/account_status,确认交易通道已连接
连接信息
从用户环境或项目 .env 读取(勿在对话中复述完整 API Key):
| 变量 | 含义 |
|---|---|
QMT_BRIDGE_HOST / 用户提供的 IP |
服务端地址 |
QMT_BRIDGE_PORT |
端口,默认 8000 |
QMT_BRIDGE_API_KEY |
交易认证密钥 |
QMT_BRIDGE_STOCK_ACCOUNT_ID |
普通证券账户(可选) |
QMT_BRIDGE_CREDIT_ACCOUNT_ID |
信用两融账户(可选) |
QMT_BRIDGE_DEFAULT_ACCOUNT |
默认户 stock / credit(默认 stock) |
Python 客户端(推荐,仓库已内置):
from qmt_bridge import QMTClient
client = QMTClient(host="192.168.1.100", port=8000, api_key="***")
curl:所有交易请求加 -H "X-API-Key: $QMT_BRIDGE_API_KEY"。
核心常量
| 字段 | 值 | 说明 |
|---|---|---|
order_type |
23 |
买入 |
order_type |
24 |
卖出 |
price_type |
5 |
最新价(默认) |
price_type |
11 |
限价(须填 price) |
price_type |
42 |
最优五档即时成交剩余撤销 |
股票代码:代码.交易所,如 000001.SZ、600519.SH。
数量:A 股通常为 100 的整数倍;卖出时使用 can_use_volume(可用数量),勿超过持仓。
操作流程
1. 查询持仓
python skills/qmt-bridge-trading/scripts/trading_status.py
或 API / 客户端:
resp = client.query_positions(account_id="") # 可选 account_id
positions = resp.get("data", resp)
持仓记录常用字段:stock_code、volume(总持仓)、can_use_volume(可卖)、open_price、market_value。
单标的持仓:GET /api/trading/position/{stock_code} 或 client.query_single_position("000001.SZ")。
2. 查询资产与委托(辅助)
asset = client.query_asset() # 资金、市值等
orders = client.query_orders() # 当日委托;cancelable_only=True 仅可撤
trades = client.query_trades() # 当日成交
3. 单笔下单
执行前必须向用户确认:标的、方向、数量、价格类型与价格。
# 预览
python skills/qmt-bridge-trading/scripts/place_order.py 000001.SZ --buy --volume 100
# 提交
python skills/qmt-bridge-trading/scripts/place_order.py 000001.SZ --buy --volume 100 --execute --confirm
result = client.place_order(
stock_code="000001.SZ",
order_type=23, # 买入
order_volume=100,
price_type=5, # 最新价
price=0.0,
strategy_name="",
order_remark="agent",
account_id="",
)
# 返回示例: {"order_id": <int>, "status": "submitted"}
curl -s -X POST "http://HOST:PORT/api/trading/order" \
-H "Content-Type: application/json" -H "X-API-Key: KEY" \
-d '{"stock_code":"000001.SZ","order_type":23,"order_volume":100,"price_type":5}'
限价示例:price_type=11, price=10.50。
4. 批量下单
请求体为 OrderRequest 数组(与单笔字段相同)。
orders = [
{"stock_code": "000001.SZ", "order_type": 23, "order_volume": 100, "price_type": 5},
{"stock_code": "600519.SH", "order_type": 24, "order_volume": 100, "price_type": 5},
]
result = client.batch_order(orders)
# 返回: {"data": [{"stock_code": "...", "order_id": ...}, ...]}
curl -s -X POST "http://HOST:PORT/api/trading/batch_order" \
-H "Content-Type: application/json" -H "X-API-Key: KEY" \
-d '[{"stock_code":"000001.SZ","order_type":23,"order_volume":100}]'
批量接口在服务端 顺序同步 调用 order(),任一笔失败会中断后续(注意部分已成功的情况)。
5. 清仓(无独立 API)
清仓 = 对持仓中 can_use_volume > 0 的标的批量 卖出(order_type=24)。
python skills/qmt-bridge-trading/scripts/liquidate.py
python skills/qmt-bridge-trading/scripts/liquidate.py --codes 000001.SZ --execute --confirm
标准流程(未用脚本时):
query_positions()获取持仓列表- 过滤:
can_use_volume > 0(可选:用户指定stock_codes子集) - 向用户展示待卖清单(代码、可卖数量、市值),获得明确确认
- 构造卖出委托列表,
price_type默认5(最新价);用户要求限价则11+price batch_order(orders)或逐笔place_order- 回报每笔
order_id;建议再查query_orders()/query_positions()核对
清仓辅助逻辑(Python 片段,可在一次性脚本中使用):
def b
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- scripts/_common.py
- scripts/liquidate.py
- scripts/place_order.py
- scripts/trading_status.py
FAQ
Что делает скилл qmt-bridge-trading?
通过 QMT Bridge HTTP API 执行证券交易:持仓/资产/委托查询、单笔与批量下单、撤单、清仓。 在用户提到 qmt-bridge 交易、下单、持仓、清仓、撤单、查询资产,或需操作 miniQMT 账户时使用。 本文件随 QMT Trading Skill(qmt-trading-skill 仓库)发布于 skills/qmt-bridge-trading/SKILL.md。
Как установить скилл qmt-bridge-trading?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл qmt-bridge-trading запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…