SuperAPI AI Directory

qmt-docs

Coding & development

View repository

Updated 10-16 00:03

About this skill

QMT Python Strategy Development Knowledge Base

Provides a complete Python development reference for QMT (XunTou Ultra-Fast Strategy Trading System), divided intoTutorial Guideand API Referencetwo levels.

📖 Documentation 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 Reference (Official Complete Documentation) └── python-innerApi/ ├── start_now.md Quick Start (backtesting/live trading overview + examples of three mechanisms) ├── 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 (account/order/deal/position main push) ├── 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 objects such as Bar/Tick/Order/Position) ├── enum_constants.md Enumeration constants (opType, orderType, order status, etc.) ├── variable_convention.md Variable conventions ├── code_examples.md Complete code example collection ├── user_attention.md User precautions └── question_answer.md Frequently asked questions

Data Dictionary └── dict/ Data fields for each variety (stock / indexes / future / option, etc.)


## 🚀 使用引导

### 按场景选择入口

| 场景 | 首先阅读 | 然后查阅 |
|------|---------|---------|
| **新手入门** | `overview.md` → `execution-mechanisms.md` | `quick-reference.md` |
| **编写回测策略** | `backtesting-guide.md` | `examples/backtest.md` |
| **编写实盘策略** | `live-trading-guide.md` | `examples/live-trading.md` |
| **查询 API 用法** | `quick-reference.md`(速查) | `python-innerApi/data_function.md` 等(完整参数) |
| **从聚宽迁移** | `joinquant-migration.md` | `overview.md` |
| **代码质量优化** | `best-practices.md` | `examples/` |
| **数据结构查询** | `python-innerApi/data_structure.md` | `python-innerApi/enum_constants.md` |

### 快速查找路径

Need to see how a function is used? → quick-reference.md (condensed version of commonly used functions) → python-innerApi/data_function.md (complete documentation for data acquisition) → python-innerApi/trading_function.md (complete documentation for trading) → 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 look up field meanings? → python-innerApi/data_structure.md (data structure definitions) → dict/ (data dictionaries for each variety)

Encountered an error/problem? → python-innerApi/question_answer.md (official FAQ) → python-innerApi/user_attention.md (precautions)


## 🔧 关键速查

### 编码规范
```python
#coding:gbk  # 必须在文件第一行

Core Concepts

Concept Description
handlebar K-line driven (recommended for backtesting)
subscribe Event-driven (live trading only, high frequency)
run_time Timed trigger (monitoring scenarios)
quicktrade=0 Wait for the K-line to complete before placing an order (bar-by-bar mode)
quicktrade=2 Place order immediately (no waiting required)
Minimum unit 100 shares

Most Commonly Used Code

# 获取历史行情数据(回测用 subscribe=False,实盘用 subscribe=True)
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])

# 获取全推实时行情
tick = C.get_full_tick(['600000.SH'])
price = tick['600000.SH']['lastPrice']

# 下单买入(23=买入, 1101=按股数, quicktrade=0 逐K线模式)
passorder(23, 1101, account, stock, 5, -1, 100, C)

# 下单买入(quicktrade=2 立即下单模式)
passorder(23, 1101, account, stock, 5, -1, 100, '策略名', 2, '备注', C)

# 查询持仓
holds = get_trade_detail_data(account, 'stock', 'position')
holds_dict = {f'{p.m_strInstrumentID}.{p.m_strExchangeID}': p.m_nVolume for p in holds}

# 查询账户可用资金(单位:分)
cash = get_trade_detail_data(account, 'stock', 'account')[0].m_dAvailable

⚠️ Usage Precautions

  1. Encoding declaration: the first line of the file must be #coding:gbk, cannot be omitted
  2. Positional arguments:get_market_data_ex the first two arguments of fields and stocks must be positional arguments, cannot use fields= or stocks=
  3. subscribe parameter: backtesting must False, use in live trading True
  4. Account type:get_trade_detail_data second parameter: for stocks use 'stock', for margin trading use 'credit'
  5. Amount unit:m_dAvailable and other amount fields usecents, need to /100 convert to yuan
  6. Quantity unit: stock trading must be an integer multiple of 100
  7. Live trading restriction:subscribe and run_time only support live trading, not backtesting