qmt-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQMT Python 策略开发知识库
QMT Python Strategy Development Knowledge Base
为 QMT(迅投极速策略交易系统)提供完整的 Python 开发参考,分为教程指南和 API 参考两层。
Provides complete Python development references for QMT (Xuntou High-Speed Strategy Trading System), divided into two layers: Tutorial Guides and API References.
📖 文档结构
📖 Document Structure
教程/指南(实践导向)
├── overview.md 系统概述、模式选择、入门路径
├── execution-mechanisms.md 三种运行机制详解(含流程图和代码模板)
├── backtesting-guide.md 回测完整流程(数据准备→参数设置→运行→分析)
├── live-trading-guide.md 实盘交易指南(账号配置→委托管理→风险控制)
├── quick-reference.md ★ 常用 API 速查卡片
├── best-practices.md 编码规范、性能优化、风险管理、调试技巧
├── joinquant-migration.md 聚宽策略迁移至 QMT 指南
└── examples/ 代码示例(backtest / live-trading / subscribe / run-time)
API 参考(官方完整文档)
└── python-innerApi/
├── start_now.md 快速开始(回测/实盘概览 + 三种机制示例)
├── data_function.md 行情与数据函数(get_market_data_ex 等完整参数)
├── trading_function.md 交易函数(passorder、get_trade_detail_data 等)
├── system_function.md 系统函数(ContextInfo 方法、定时器等)
├── callback_function.md 回调函数(account/order/deal/position 主推)
├── quote_function.md 引用函数(扩展数据、因子、VBA调用)
├── drawing_function.md 绘图函数
├── interface_operation.md 界面操作说明
├── data_structure.md 数据结构定义(Bar/Tick/Order/Position 等对象字段)
├── enum_constants.md 枚举常量(opType、orderType、委托状态等)
├── variable_convention.md 变量约定
├── code_examples.md 完整代码示例合集
├── user_attention.md 用户注意事项
└── question_answer.md 常见问题
数据字典
└── dict/ 各品种数据字段(stock / indexes / future / option 等)Tutorials/Guides (Practice-Oriented)
├── overview.md System overview, mode selection, getting started path
├── execution-mechanisms.md Detailed explanation of three operation mechanisms (including flowcharts and code templates)
├── backtesting-guide.md Complete backtesting process (data preparation → parameter setting → execution → analysis)
├── live-trading-guide.md Live trading guide (account configuration → order management → risk control)
├── quick-reference.md ★ Quick reference card for commonly used APIs
├── best-practices.md Coding standards, performance optimization, risk management, debugging techniques
├── joinquant-migration.md Guide for migrating JoinQuant strategies to QMT
└── examples/ Code examples (backtest / live-trading / subscribe / run-time)
API References (Official Complete Documentation)
└── python-innerApi/
├── start_now.md Quick start (backtest/live trading overview + three mechanism examples)
├── data_function.md Market and data functions (complete parameters for get_market_data_ex, etc.)
├── trading_function.md Trading functions (passorder, get_trade_detail_data, etc.)
├── system_function.md System functions (ContextInfo methods, timers, etc.)
├── callback_function.md Callback functions (push for account/order/deal/position)
├── quote_function.md Reference functions (extended data, factors, VBA calls)
├── drawing_function.md Drawing functions
├── interface_operation.md Interface operation instructions
├── data_structure.md Data structure definitions (fields of Bar/Tick/Order/Position objects, etc.)
├── enum_constants.md Enumeration constants (opType, orderType, order status, etc.)
├── variable_convention.md Variable conventions
├── code_examples.md Collection of complete code examples
├── user_attention.md User notes
└── question_answer.md Frequently asked questions
Data Dictionary
└── dict/ Data fields for various varieties (stock / indexes / future / option, etc.)🚀 使用引导
🚀 Usage Guide
按场景选择入口
Select Entry by Scenario
| 场景 | 首先阅读 | 然后查阅 |
|---|---|---|
| 新手入门 | | |
| 编写回测策略 | | |
| 编写实盘策略 | | |
| 查询 API 用法 | | |
| 从聚宽迁移 | | |
| 代码质量优化 | | |
| 数据结构查询 | | |
| Scenario | Read First | Then Refer To |
|---|---|---|
| Beginner Getting Started | | |
| Writing Backtesting Strategies | | |
| Writing Live Trading Strategies | | |
| Querying API Usage | | |
| Migrating from JoinQuant | | |
| Optimizing Code Quality | | |
| Querying Data Structures | | |
快速查找路径
Quick Lookup Path
需要看函数怎么用?
→ quick-reference.md(常用函数精简版)
→ python-innerApi/data_function.md(数据获取类完整文档)
→ python-innerApi/trading_function.md(交易类完整文档)
→ python-innerApi/system_function.md(系统/ContextInfo 方法)
需要看完整代码?
→ python-innerApi/code_examples.md(官方示例合集)
→ examples/(精选示例)
需要查字段含义?
→ python-innerApi/data_structure.md(数据结构定义)
→ dict/(各品种数据字典)
遇到报错/问题?
→ python-innerApi/question_answer.md(官方FAQ)
→ python-innerApi/user_attention.md(注意事项)Need to know how to use a function?
→ quick-reference.md (simplified version of commonly used functions)
→ python-innerApi/data_function.md (complete documentation for data acquisition functions)
→ python-innerApi/trading_function.md (complete documentation for trading functions)
→ python-innerApi/system_function.md (system/ContextInfo methods)
Need to see complete code?
→ python-innerApi/code_examples.md (official example collection)
→ examples/ (selected examples)
Need to check field meanings?
→ python-innerApi/data_structure.md (data structure definitions)
→ dict/ (data dictionaries for various varieties)
Encounter errors/issues?
→ python-innerApi/question_answer.md (official FAQ)
→ python-innerApi/user_attention.md (notes)🔧 关键速查
🔧 Key Quick Reference
编码规范
Coding Standards
python
#coding:gbk # 必须在文件第一行python
#coding:gbk # Must be on the first line of the file核心概念
Core Concepts
| 概念 | 说明 |
|---|---|
| handlebar | K线驱动(回测推荐) |
| subscribe | 事件驱动(仅实盘,高频) |
| run_time | 定时触发(监控场景) |
| quicktrade=0 | 等待K线完成再下单(逐K线模式) |
| quicktrade=2 | 立即下单(不需要等待) |
| 最小单位 | 100 股 |
| Concept | Description |
|---|---|
| handlebar | K-line driven (recommended for backtesting) |
| subscribe | Event-driven (live trading only, high frequency) |
| run_time | Scheduled trigger (monitoring scenarios) |
| quicktrade=0 | Place order after K-line is completed (per K-line mode) |
| quicktrade=2 | Place order immediately (no waiting required) |
| Minimum Unit | 100 shares |
最常用代码
Most Commonly Used Code
python
undefinedpython
undefined获取历史行情数据(回测用 subscribe=False,实盘用 subscribe=True)
Get historical market data (use subscribe=False for backtesting, subscribe=True for live trading)
data = C.get_market_data_ex(['close'], [stock], end_time=bar_date,
period='1d', count=100, subscribe=False)
close_list = list(data[stock].iloc[:, 0])
data = C.get_market_data_ex(['close'], [stock], end_time=bar_date,
period='1d', count=100, subscribe=False)
close_list = list(data[stock].iloc[:, 0])
获取全推实时行情
Get full push real-time market data
tick = C.get_full_tick(['600000.SH'])
price = tick['600000.SH']['lastPrice']
tick = C.get_full_tick(['600000.SH'])
price = tick['600000.SH']['lastPrice']
下单买入(23=买入, 1101=按股数, quicktrade=0 逐K线模式)
Place buy order (23=Buy, 1101=By share count, quicktrade=0 per K-line mode)
passorder(23, 1101, account, stock, 5, -1, 100, C)
passorder(23, 1101, account, stock, 5, -1, 100, C)
下单买入(quicktrade=2 立即下单模式)
Place buy order (quicktrade=2 immediate order mode)
passorder(23, 1101, account, stock, 5, -1, 100, '策略名', 2, '备注', C)
passorder(23, 1101, account, stock, 5, -1, 100, 'Strategy Name', 2, 'Remarks', C)
查询持仓
Query positions
holds = get_trade_detail_data(account, 'stock', 'position')
holds_dict = {f'{p.m_strInstrumentID}.{p.m_strExchangeID}': p.m_nVolume for p in holds}
holds = get_trade_detail_data(account, 'stock', 'position')
holds_dict = {f'{p.m_strInstrumentID}.{p.m_strExchangeID}': p.m_nVolume for p in holds}
查询账户可用资金(单位:分)
Query available account funds (unit: cents)
cash = get_trade_detail_data(account, 'stock', 'account')[0].m_dAvailable
undefinedcash = get_trade_detail_data(account, 'stock', 'account')[0].m_dAvailable
undefined⚠️ 使用注意事项
⚠️ Usage Notes
- 编码声明:文件首行必须是 ,不可省略
#coding:gbk - 位置参数:的前两个参数
get_market_data_ex和fields必须用位置参数,不能用stocks或fields=stocks= - subscribe 参数:回测必须 ,实盘使用
FalseTrue - 账号类型:的第二个参数:股票用
get_trade_detail_data,两融用'stock''credit' - 金额单位:等金额字段单位是分,需
m_dAvailable转换为元/100 - 数量单位:股票交易必须是 100 的整数倍
- 实盘限制:和
subscribe仅支持实盘,不支持回测run_time
- Encoding Declaration: The first line of the file must be , which cannot be omitted
#coding:gbk - Positional Parameters: The first two parameters and
fieldsofstocksmust be positional parameters, cannot useget_market_data_exorfields=stocks= - subscribe Parameter: Must be for backtesting, use
Falsefor live tradingTrue - Account Type: The second parameter of : use
get_trade_detail_datafor stocks,'stock'for margin trading'credit' - Amount Unit: Amount fields such as are in cents, need to divide by 100 to convert to yuan
m_dAvailable - Quantity Unit: Stock trading must be in integer multiples of 100
- Live Trading Restrictions: and
subscribeonly support live trading, not backtestingrun_time