通过 QMT Bridge HTTP API 执行证券交易,支持持仓/资产/委托查询、单笔与批量下单、撤单、清仓。适用于操作 miniQMT 账户进行 A 股交易。
Ships in qmt-trading-skill. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
发布位置:
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(可用数量),勿超过持仓。
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")。
asset = client.query_asset() # 资金、市值等
orders = client.query_orders() # 当日委托;cancelable_only=True 仅可撤
trades = client.query_trades() # 当日成交
执行前必须向用户确认:标的、方向、数量、价格类型与价格。
# 预览
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。
请求体为 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(),任一笔失败会中断后续(注意部分已成功的情况)。
清仓 = 对持仓中 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 + pricebatch_order(orders) 或逐笔 place_orderorder_id;建议再查 query_orders() / query_positions() 核对清仓辅助逻辑(Python 片段,可在一次性脚本中使用):
def build_liquidation_orders(positions, price_type=5, price=0.0, account_id="", remark="liquidate"):
sell_type = 24
items = positions if isinstance(positions, list) else []
orders = []
for p in items:
vol = int(p.get("can_use_volume") or 0)
code = p.get("stock_code") or p.get("stockCode")
if not code or vol <= 0:
continue
orders.append({
"stock_code": code,
"order_type": sell_type,
"order_volume": vol,
"price_type": price_type,
"price": price,
"order_remark": remark,
"account_id": account_id,
})
return orders
positions = client.query_positions().get("data", [])
orders = build_liquidation_orders(positions)
if orders:
client.batch_order(orders)
注意:T+1 导致当日买入不可卖;科创板/创业板等可能有不同最小单位;停牌、涨跌停可能导致废单。
client.cancel_order(order_id=12345, account_id="")
# 批量: client.batch_cancel([{"order_id": 1}, {"order_id": 2}])
curl -s -X POST "http://HOST:PORT/api/trading/cancel" \
-H "Content-Type: application/json" -H "X-API-Key: KEY" \
-d '{"order_id":12345}'
6_交易管理.py 的确认流程)。query_positions + query_asset。logging,勿 print 敏感 Key。scripts/,勿在仓库外留下一次性交易脚本。多数查询接口返回 {"data": ...};下单返回 {"order_id": ..., "status": "submitted"}。客户端 query_* 可能直接返回外层 dict,用 .get("data", resp) 统一取列表/对象。
| 操作 | 方法 | 路径 |
|---|---|---|
| 下单 | POST | /api/trading/order |
| 批量下单 | POST | /api/trading/batch_order |
| 撤单 | POST | /api/trading/cancel |
| 批量撤单 | POST | /api/trading/batch_cancel |
| 持仓 | GET | /api/trading/positions |
| 资产 | GET | /api/trading/asset |
| 委托 | GET | /api/trading/orders |
| 成交 | GET | /api/trading/trades |
| 账户状态 | GET | /api/trading/account_status |
完整列表见 Bridge REST API 与 trading 客户端。
用户:查一下当前持仓
Agent:query_positions → 表格展示 stock_code / volume / can_use_volume / market_value
用户:限价 10.5 买入 000001.SZ 100 股
Agent:确认参数 → place_order(..., order_type=23, price_type=11, price=10.5) → 返回 order_id
用户:全部清仓
Agent:拉持仓 → 列出可卖标的与数量 → 用户确认 → build_liquidation_orders + batch_order → 汇总 order_id 并建议刷新持仓
What SKILL.md sets; muted values are Claude Code's defaults
23 skills in this plugin
/qmt-bridge-convertible通过 QMT Bridge 查询可转债列表与条款信息,辅助转债双低、强赎等策略观察。 在用户提到可转债、转债、强赎、转股时使用。只读。/qmt-bridge-credit-margin通过 QMT Bridge 查询融资融券账户:担保品、可用保证金、信用相关交易端点。 在用户提到两融、融资融券、保证金、信用账户时使用。按需启用;写操作须确认。/qmt-bridge-daily-pnl通过 QMT Bridge 查看当日盈亏:结合当前持仓、昨仓与当日买卖成交计算,含已清仓标的。 在用户提到今日盈亏、当日收益、赚了多少、盘面盈亏时使用。只读。/qmt-bridge-etf通过 QMT Bridge 查询 ETF 列表、申赎清单与相关行情,辅助 ETF 投资与套利观察。 在用户提到 ETF、申赎、指数基金、ETF 套利时使用。只读。/qmt-bridge-event-calendar通过 QMT Bridge 查询交易日历、节假日、交易时段,并支持用户自定义的财报/持仓事件检查规程。 在用户提到是否交易日、节假日、交易时间、财报日、日历时使用。只读。/qmt-bridge-execution-review通过 QMT Bridge 生成当日交易复盘:客观证据(委托/成交/滑点/不操作基线/规则标签)+ Agent 层投顾/基金经理/交易员三角色专家评审与综合裁决。 在用户提到今日成交、交易复盘、今日操作评估、执行质量、三角色复盘、专家复盘、 不操作少赚多亏时使用。只读。/atorber-qmt-trading-skill:qmt-bridge-tradingfrom qmt-trading-skill
Generated from the plugin's indexed repository (atorber/qmt-trading-skill) — no native marketplace selected
npx claudepluginhub p/atorber-qmt-trading-skillOther plugins' skills for the same job