
qmt-strategy
QMT 客户端(迅投极速策略交易系统)内置 Python 策略引擎开发指南,涵盖策略编写、回测、实盘交易、内置 API 参考与代码示例(基于 ContextInfo/passorder/gettradedetaildata 等,非 xtquant 库)。当用户需要在 QMT 客户端中编写/回测/运行策略、查询 QMT 内置 API、从聚宽迁移至 QMT,或提及 QMT 策略、迅投策略、QMT 回测时使用;直接提及 passorder、ContextInfo、handlebar、getmarketdataex、gettradedetaildata 等内置 API,或描述 QMT 策略报错、回测无成交、GBK 编码报错等问题时同样适用。外部 xtquant/xtdata 连接场景不适用,请用 miniqmt 技能。
- Installs
- 46
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/lzwme/finance-quant-skills --skill qmt-strategy- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads qmt-strategy automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
QMT Python 策略开发知识库
⛔ 铁律:输出的一切代码只能使用 QMT 内置 API(
ContextInfo/passorder/get_trade_detail_data等)。代码中出现xtdata/xttrader/import jqdata即为错误输出。
本技能面向 QMT 客户端内置策略引擎——策略在 QMT 客户端内运行,使用内置 API(ContextInfo/C、passorder、get_market_data_ex、get_trade_detail_data 等),文件首行需 #coding:gbk。若需在外部 Python 程序中通过 xtquant 库(xtdata/xttrader)连接 QMT/MiniQMT 客户端获取行情或下单,请使用 miniqmt 技能。
📖 文档路由
全部文档位于 references/ 目录,按场景按需读取,不要一次全读:
| 场景 | 读取文件 | 何时读取 |
|---|---|---|
| 新手入门 / 选运行机制 | references/overview.md → references/execution-mechanisms.md | 首次接触 QMT,或不确定 handlebar/subscribe/run_time 该用哪个 |
| API 速查 | references/quick-reference.md | 只需确认函数签名、常用参数、枚举取值;末尾骨架含 TODO 占位信号,交付前必须替换 |
| 编写回测策略 | references/backtesting-guide.md → references/examples/backtest.md | 需要完整回测流程、参数设置与可运行模板 |
| 编写实盘策略 | references/live-trading-guide.md → references/examples/live-trading.md | 涉及账号配置、委托管理、风险控制 |
| 事件驱动 / 定时任务 | references/examples/subscribe.md、references/examples/run-time.md | 需要用 subscribe 或 run_time 模式 |
| 从聚宽迁移 | references/joinquant-migration.md | 已有聚宽策略需改写为 QMT 内置写法 |
| 代码质量与调试 | references/best-practices.md | 需要编码规范、性能优化、常见陷阱 |
| 函数完整参数 | references/python-innerApi/data_function.md、references/python-innerApi/trading_function.md、references/python-innerApi/system_function.md | 速查卡不够用,需查全部参数与返回值 |
| 回调函数 | references/python-innerApi/callback_function.md | 需要 account/order/deal/position 主推回调 |
| 数据结构与枚举 | references/python-innerApi/data_structure.md、references/python-innerApi/enum_constants.md | 查 m_* 字段含义、opType/orderType/委托状态取值 |
| 报错与数据缺失 | references/python-innerApi/question_answer.md、references/dict/question_answer.md | 连不上服务、K线缺失、订阅失效、数据更新时间疑问 |
| 品种数据字段 | references/dict/stock.md、references/dict/future.md、references/dict/option.md、references/dict/indexes.md、references/dict/bond.md、references/dict/floorfunds.md、references/dict/industry.md、references/dict/xuntou_factor.md | 查某品种特有字段(财务、期权希腊字母、因子等) |
| 官方示例合集 | references/python-innerApi/code_examples.md | 需要更多可运行范例 |
| 界面与变量约定 | references/python-innerApi/interface_operation.md、references/python-innerApi/variable_convention.md | 配置回测/实盘界面,或确认周期、代码格式等约定 |
| 其余章节 | references/python-innerApi/start_now.md、references/python-innerApi/quote_function.md、references/python-innerApi/drawing_function.md、references/python-innerApi/user_attention.md、references/dict/scenario_based_example.md | 快速开始、扩展数据/因子引用、K线绘图标注、官方注意事项、场景化示例 |
🚦 执行流程
- 判定场景(回测 / 实盘 / 仅查 API),按上表读 1~2 个文件;不整目录加载。
- ⛔ 实盘确认门:涉及真实账号、
passorder或写入策略文件时,先确认账号类型(stock/credit/FUTURE)、是否模拟信号模式、标的代码、单笔数量;未确认前只给模板,不填真实账号、不产出可直接运行的实盘下单代码。 - 输出完整策略文件(首行
#coding:gbk,含init/handlebar),不只贴片段。 - ⚠️ 逐条执行「交付前自检」,把未通过项明确列出。
🔧 关键速查
核心概念
| 概念 | 说明 |
|---|---|
| handlebar | 逐K线驱动(回测默认) |
| subscribe / run_time | 事件 / 定时驱动,仅实盘,回测不可用 |
| quicktrade=0 | 逐K线:下一根K线首个 tick 触发(默认值) |
| quicktrade=1 | 立即下单,仅非历史 bar(C.is_last_bar() 为 True 时触发) |
| quicktrade=2 | 立即下单且不判断 bar,历史 bar 也会触发,⚠️ 仅在明确知情时使用 |
| 编码与单位 | 文件首行 #coding:gbk;股票下单量必须是 100 的整数倍 |
2会在历史 bar 上也发出委托;subscribe/run_time回调没有 K 线上下文,官方示例用2。取值含义见references/python-innerApi/trading_function.md。
最常用代码(签名速记)
C.get_market_data_ex(['close'], [stock], end_time=bar_date, period='1d', count=100, subscribe=False)
C.get_full_tick(['600000.SH']) # 仅实盘
passorder(23, 1101, account, stock, 5, -1, 100, C) # 8 参数短式,quicktrade 缺省为 0
passorder(23, 1101, account, stock, 5, -1, 100, '策略名', 1, '备注', C) # 11 参数式,实盘立即下单
get_trade_detail_data(account, 'stock', 'position') # 持仓
get_trade_detail_data(account, 'stock', 'account')[0].m_dAvailable # 可用资金(float,元)
get_market_data_ex的fields、stocks必须位置传参;回测subscribe=False,实盘True。- 以上是片段。交付完整策略文件时必须补首行
#coding:gbk与init/handlebar骨架,C/stock/account/bar_date需在init中定义;完整模板见references/quick-reference.md与references/examples/,其中TODO占位信号必须替换。
⚠️ 交付前自检
生成或修改任何 QMT 策略代码后,逐条核对:
- 编码声明:文件首行
#coding:gbk,不可省略 - 位置参数:
get_market_data_ex的fields、stocks必须位置传参,写成fields=/stocks=会报错 - subscribe:回测
False,实盘True;subscribe/run_time运行模式仅实盘支持,回测不可用 - 账号类型:
get_trade_detail_data第二参数,股票'stock'、两融'credit'、期货'FUTURE' - 金额单位:
m_dAvailable等资金字段是 float,单位元,可直接参与计算;若下单量恰为预期 100 倍,才检查该账户是否按分返回 - 数量单位:股票下单量必须是 100 的整数倍
- quicktrade:实盘
handlebar立即下单用1;2会让历史 bar 也触发委托,仅在用户明确要求时使用 - 完整文件:交付的是可运行策略文件(编码声明 +
init/handlebar),不是无骨架片段;模板中TODO占位信号已全部替换 - API 边界:无
xtdata/xttrader/聚宽 API 混入
📄 文档来源与合规
references/ 根目录文档与 references/examples/ 为本技能作者原创整理;references/python-innerApi/、references/dict/ 为迅投官方知识库(dict.thinktrader.net)离线快照,版权归迅投所有,各文件首部保留官方原文 url 与 title。官方层内容仅作离线查阅与内部学习参考,对外分发、转载或商业使用请以迅投官方知识库为准并遵守其使用条款;原创主张仅适用于原创教程层内容。
FAQ
What does the qmt-strategy skill do?
QMT 客户端(迅投极速策略交易系统)内置 Python 策略引擎开发指南,涵盖策略编写、回测、实盘交易、内置 API 参考与代码示例(基于 ContextInfo/passorder/gettradedetaildata 等,非 xtquant 库)。当用户需要在 QMT 客户端中编写/回测/运行策略、查询 QMT 内置 API、从聚宽迁移至 QMT,或提及 QMT 策略、迅投策略、QMT 回测时使用;直接提及 passorder、ContextInfo、handlebar、getmarketdataex、gettradedetaildata 等内置 API,或描述 QMT 策略报错、回测无成交、GBK 编码报错等问题时同样适用。外部 xtquant/xtdata 连接场景不适用,请用 miniqmt 技能。
How do I install qmt-strategy?
Run npx skills add https://github.com/lzwme/finance-quant-skills --skill qmt-strategy in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/qmt-strategy/ (personal) or .claude/skills/qmt-strategy/ (project).
Which AI agents can use qmt-strategy?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is qmt-strategy safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains qmt-strategy?
It is published by lzwme in lzwme/finance-quant-skills. It has 46 recorded installs.
More from lzwme/finance-quant-skills
pywencai
lzwme/finance-quant-skills
同花顺问财数据查询:使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据;当用户需要通过自然语言从问财获取选股、财务、资金流、技术指标等数据时使用。
akshare
lzwme/finance-quant-skills
AKShare 开源金融数据接口库,提供股票、期货、期权、基金、外汇、债券、指数、加密货币等全品类金融数据;当用户需要获取各类金融市场数据时使用
baostock
lzwme/finance-quant-skills
BaoStock 免费开源 A 股数据平台,无需注册、无需 API Key,支持股票行情、K线、财务数据、行业分类、指数成分股查询。当用户提及 baostock、需要获取A股历史行情、财务报表、交易日历,或需要免费、免注册的A股数据时使用。与 tushare(数据更全但需注册)和 jqdatasdk(聚宽数据)不同,baostock 完全免费无限制,适合快速入门和低成本数据需求。
tdxquant
lzwme/finance-quant-skills
通达信量化数据获取技能。当用户提及 tdxquant、通达信、TdxQuant、tqcenter,并且需要获取A股数据(行情快照、K线、财务、板块、可转债、新股、交易数据等)、查询交易日历、执行通达信公式、订阅行情、交易下单时使用
backtrader
lzwme/finance-quant-skills
Backtrader 开源量化回测框架,支持多数据源、多策略、多周期回测与实盘交易,纯Python实现。当用户需要开发量化策略、进行回测分析、编写交易逻辑、回测参数优化,或提及 backtrader、量化回测框架时使用。若用户仅需数据获取而无回测需求,引导使用 baostock/akshare/tushare 等数据 Skill。
miniqmt
lzwme/finance-quant-skills
MiniQMT 迅投量化交易接口,基于 XtQuant Python 库(xtdata 行情 / xttrader 交易),供外部 Python 程序连接 MiniQMT 客户端,支持 A 股/期货/期权的行情获取(K线、分笔、财务数据等)和交易下单(报单、撤单、查询资产/委托/持仓)。当用户提及 miniqmt、xtquant、获取实时行情、量化交易下单、回测数据获取,或需要用外部 Python 程序连接 MiniQMT 客户端进行程序化交易时使用。若需在 QMT 客户端内编写/回测内置策略(ContextInfo/passorder),请用 qmt-strategy 技能。
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.