miniqmt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMiniQMT 量化交易技能
MiniQMT Quantitative Trading Skill
任务目标
Task Objectives
- 本 Skill 用于:通过 XtQuant 库连接 MiniQMT 客户端,获取 A 股/期货/期权行情数据,执行量化交易操作
- 能力包含:
- 行情模块 (xtdata):K线数据、分笔数据、实时行情订阅、财务数据、板块分类、ETF信息、新股申购、交易日历
- 交易模块 (xttrader):股票/期货/期权下单、撤单、查询资产/委托/持仓、资金划拨、信用交易、约券
- 触发条件:用户提及 miniqmt、xtquant、迅投、获取行情、量化交易、下单交易时使用
- This Skill is used to: connect to the MiniQMT client via the XtQuant library, obtain market data for A-shares, futures, and options, and execute quantitative trading operations
- Capabilities include:
- Market Module (xtdata): K-line data, tick data, real-time market subscription, financial data, sector classification, ETF information, IPO subscription, trading calendar
- Trading Module (xttrader): Stock/futures/options order placement, order cancellation, asset/order/position query, fund transfer, margin trading, securities lending
- Trigger conditions: Used when users mention miniqmt, xtquant, Xuntou, market data acquisition, quantitative trading, or order placement
前置准备
Preparations
MiniQMT 环境要求
MiniQMT Environment Requirements
- 客户端安装:需安装迅投极速交易终端,并启动 MiniQMT(支持模拟/实盘)
- Python 库:
pip install xtquant - 路径配置:MiniQMT 安装目录下的 路径用于 xttrader 连接
userdata_mini
- Client Installation: Need to install Xuntou Extreme Speed Trading Terminal and start MiniQMT (supports simulation/live trading)
- Python Library:
pip install xtquant - Path Configuration: The path under the MiniQMT installation directory is used for xttrader connection
userdata_mini
目录结构
Directory Structure
QMT安装目录\
├── bin.x64\XtMiniQmt.exe # MiniQMT 主程序
├── userdata_mini\ # 用户数据目录(xttrader 连接路径)
│ ├── xqtrader.ini # 交易配置
│ └── xtdatacenter.ini # 行情配置QMT安装目录\
├── bin.x64\XtMiniQmt.exe # MiniQMT 主程序
├── userdata_mini\ # 用户数据目录(xttrader 连接路径)
│ ├── xqtrader.ini # 交易配置
│ └── xtdatacenter.ini # 行情配置核心概念
Core Concepts
证券代码格式
Security Code Format
- 股票:6位数字 + 市场后缀,如 (上海)、
600000.SH(深圳)000001.SZ - 期货:品种代码 + 合约月份,如 (螺纹钢)
rb2405.SF - 期权:标的代码 + 行权月份,如 (上证50ETF期权)
510050.SH
- Stocks: 6-digit number + market suffix, e.g., (Shanghai),
600000.SH(Shenzhen)000001.SZ - Futures: Product code + contract month, e.g., (Rebar)
rb2405.SF - Options: Underlying code + exercise month, e.g., (SSE 50 ETF Option)
510050.SH
周期类型 (period)
Period Type (period)
| 周期 | 说明 | 周期 | 说明 |
|---|---|---|---|
| 分笔数据 | | 季度线 |
| 1分钟线 | | 半年线 |
| 5分钟线 | | 年线 |
| 15分钟线 | | 周线 |
| 30分钟线 | | 日线 |
| 1小时线 | | 月线 |
| Period | Description | Period | Description |
|---|---|---|---|
| Tick data | | Quarterly line |
| 1-minute line | | Semi-annual line |
| 5-minute line | | Annual line |
| 15-minute line | | Weekly line |
| 30-minute line | | Daily line |
| 1-hour line | | Monthly line |
复权类型 (dividend_type)
Dividend Adjustment Type (dividend_type)
- - 不复权
none - - 前复权
front - - 后复权
back - - 等比前复权
front_ratio - - 等比后复权
back_ratio
- - No adjustment
none - - Forward adjustment
front - - Backward adjustment
back - - Equal ratio forward adjustment
front_ratio - - Equal ratio backward adjustment
back_ratio
交易市场 (market)
Trading Market (market)
| 市场 | 常量 | 市场 | 常量 |
|---|---|---|---|
| 上海 | | 中金所 | |
| 深圳 | | 上期所 | |
| 北交所 | | 郑商所 | |
| 大商所 | | 广期所 | |
| Market | Constant | Market | Constant |
|---|---|---|---|
| Shanghai | | CFFEX | |
| Shenzhen | | SHFE | |
| Beijing Stock Exchange | | CZCE | |
| DCE | | GFEX | |
账号类型 (account_type)
Account Type (account_type)
| 类型 | 常量 | 类型 | 常量 |
|---|---|---|---|
| 股票 | | 沪港通 | |
| 期货 | | 深港通 | |
| 信用 | | 期货期权 | |
| 股票期权 | | - | - |
| Type | Constant | Type | Constant |
|---|---|---|---|
| Stock | | Shanghai-Hong Kong Stock Connect | |
| Futures | | Shenzhen-Hong Kong Stock Connect | |
| Margin | | Futures Option | |
| Stock Option | | - | - |
操作步骤
Operation Steps
- 确定需求 — 识别是行情数据获取还是交易操作
- 选择模块 — xtdata 用于行情,xttrader 用于交易
- 调用脚本 — 根据数据类型选择对应脚本
- 解析结果 — 智能体分析返回的 JSON 格式数据
- Confirm Requirements — Identify whether it is market data acquisition or trading operation
- Select Module — Use xtdata for market data, xttrader for trading
- Call Script — Select the corresponding script based on data type
- Parse Results — The agent analyzes the returned JSON format data
意图识别映射示例
Intent Recognition Mapping Examples
| 用户提问 | 对应功能 | 调用方式 |
|---|---|---|
| "贵州茅台实时股价" | 实时行情快照 | xtdata.get_full_tick |
| "平安银行K线数据" | K线数据 | xtdata.get_market_data |
| "招商银行财务指标" | 财务报表 | xtdata.get_financial_data |
| "半导体板块成分股" | 板块成分股 | xtdata.get_stock_list_in_sector |
| "今日可转债信息" | ETF/可转债数据 | xtdata.get_cb_info |
| "新股申购" | 新股信息 | xtdata.get_ipo_info |
| "下单买入平安银行" | 交易下单 | xttrader.order_stock |
| "查询持仓" | 持仓查询 | xttrader.query_stock_positions |
| "撤单" | 撤单操作 | xttrader.cancel_order_stock |
| User Query | Corresponding Function | Calling Method |
|---|---|---|
| "贵州茅台实时股价" | Real-time market snapshot | xtdata.get_full_tick |
| "平安银行K线数据" | K-line data | xtdata.get_market_data |
| "招商银行财务指标" | Financial statements | xtdata.get_financial_data |
| "半导体板块成分股" | Sector constituent stocks | xtdata.get_stock_list_in_sector |
| "今日可转债信息" | ETF/convertible bond data | xtdata.get_cb_info |
| "新股申购" | IPO information | xtdata.get_ipo_info |
| "下单买入平安银行" | Trading order placement | xttrader.order_stock |
| "查询持仓" | Position query | xttrader.query_stock_positions |
| "撤单" | Order cancellation | xttrader.cancel_order_stock |
使用示例
Usage Examples
示例1:获取股票实时行情
Example 1: Get Real-time Stock Market Data
python
import xtdatapython
import xtdata获取全推行情快照
获取全推行情快照
ticks = xtdata.get_full_tick(['600519.SH', '000001.SZ'])
ticks = xtdata.get_full_tick(['600519.SH', '000001.SZ'])
订阅单股实时行情
订阅单股实时行情
def on_data(datas):
for code in datas:
print(code, datas[code])
xtdata.subscribe_quote('600519.SH', period='tick', callback=on_data)
xtdata.run()
undefineddef on_data(datas):
for code in datas:
print(code, datas[code])
xtdata.subscribe_quote('600519.SH', period='tick', callback=on_data)
xtdata.run()
undefined示例2:获取K线历史数据
Example 2: Get Historical K-line Data
python
import xtdatapython
import xtdata下载历史K线数据
下载历史K线数据
xtdata.download_history_data2(['600519.SH'], period='1d', start_time='')
xtdata.download_history_data2(['600519.SH'], period='1d', start_time='')
获取K线数据
获取K线数据
data = xtdata.get_market_data(
field_list=['open', 'high', 'low', 'close', 'volume'],
stock_list=['600519.SH'],
period='1d',
start_time='20240101',
end_time='',
count=100,
dividend_type='front'
)
undefineddata = xtdata.get_market_data(
field_list=['open', 'high', 'low', 'close', 'volume'],
stock_list=['600519.SH'],
period='1d',
start_time='20240101',
end_time='',
count=100,
dividend_type='front'
)
undefined示例3:交易下单
Example 3: Trading Order Placement
python
from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
from xtquant.xttype import StockAccount
from xtquant import xtconstantpython
from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
from xtquant.xttype import StockAccount
from xtquant import xtconstant配置路径和会话
配置路径和会话
path = 'D:\迅投极速交易终端\userdata_mini'
session_id = 123456
xt_trader = XtQuantTrader(path, session_id)
path = 'D:\迅投极速交易终端\userdata_mini'
session_id = 123456
xt_trader = XtQuantTrader(path, session_id)
创建账号对象
创建账号对象
acc = StockAccount('1000000365') # 替换为实际账号
acc = StockAccount('1000000365') # 替换为实际账号
连接交易
连接交易
xt_trader.start()
connect_result = xt_trader.connect()
subscribe_result = xt_trader.subscribe(acc)
xt_trader.start()
connect_result = xt_trader.connect()
subscribe_result = xt_trader.subscribe(acc)
下单买入
下单买入
order_id = xt_trader.order_stock(
acc,
'600519.SH',
xtconstant.STOCK_BUY,
100, # 100股
xtconstant.FIX_PRICE,
1800.0, # 价格
'strategy1',
'remark'
)
order_id = xt_trader.order_stock(
acc,
'600519.SH',
xtconstant.STOCK_BUY,
100, # 100股
xtconstant.FIX_PRICE,
1800.0, # 价格
'strategy1',
'remark'
)
查询资产
查询资产
asset = xt_trader.query_stock_asset(acc)
print(f"可用资金: {asset.cash}")
undefinedasset = xt_trader.query_stock_asset(acc)
print(f"可用资金: {asset.cash}")
undefined示例4:订阅行情并实时处理
Example 4: Subscribe to Market Data and Process in Real-time
python
import xtdata
def on_tick_data(datas):
for code in datas:
tick = datas[code]
print(f"{code}: 现价={tick['lastPrice']}, 成交量={tick['volume']}")python
import xtdata
def on_tick_data(datas):
for code in datas:
tick = datas[code]
print(f"{code}: 现价={tick['lastPrice']}, 成交量={tick['volume']}")订阅多只股票
订阅多只股票
xtdata.subscribe_whole_quote(['SH', 'SZ'], callback=on_tick_data)
xtdata.run()
undefinedxtdata.subscribe_whole_quote(['SH', 'SZ'], callback=on_tick_data)
xtdata.run()
undefined资源索引
Resource Index
行情数据脚本
Market Data Scripts
- 行情快照:
python scripts/market_data.py snapshot --code 600519.SH - K线数据:
python scripts/market_data.py kline --code 600519.SH --period 1d --count 100 - 分笔数据:
python scripts/market_data.py tick --code 600519.SH --count 100 - 实时行情:
python scripts/market_data.py full_tick --codes 600519.SH,000001.SZ
- Market Snapshot:
python scripts/market_data.py snapshot --code 600519.SH - K-line Data:
python scripts/market_data.py kline --code 600519.SH --period 1d --count 100 - Tick Data:
python scripts/market_data.py tick --code 600519.SH --count 100 - Real-time Market:
python scripts/market_data.py full_tick --codes 600519.SH,000001.SZ
板块与财务脚本
Sector and Financial Scripts
- 板块列表:
python scripts/sector_data.py sector_list - 板块成分股:
python scripts/sector_data.py sector_stocks --sector 半导体 - 财务数据:
python scripts/financial_data.py financial --code 600519.SH --tables Balance,Income
- Sector List:
python scripts/sector_data.py sector_list - Sector Constituent Stocks:
python scripts/sector_data.py sector_stocks --sector 半导体 - Financial Data:
python scripts/financial_data.py financial --code 600519.SH --tables Balance,Income
交易脚本
Trading Scripts
- 下单:
python scripts/trade.py order --code 600519.SH --type buy --volume 100 --price 1800.0 - 撤单:
python scripts/trade.py cancel --order_id 12345 - 查询持仓:
python scripts/trade.py positions - 查询委托:
python scripts/trade.py orders - 查询资产:
python scripts/trade.py asset - 查询成交:
python scripts/trade.py trades
- Order Placement:
python scripts/trade.py order --code 600519.SH --type buy --volume 100 --price 1800.0 - Order Cancellation:
python scripts/trade.py cancel --order_id 12345 - Position Query:
python scripts/trade.py positions - Order Query:
python scripts/trade.py orders - Asset Query:
python scripts/trade.py asset - Trade Query:
python scripts/trade.py trades
参考文档
Reference Documents
- xtdata 行情模块 API(何时读取:需要查看行情数据接口时)
- xtdata行情数据字段与数据字典 (何时读取:需要查看行情数据字段、数据字典时)
- xttrader 交易模块 API(何时读取:需要查看交易接口、数据结构说明时)
- 安装与下载指南(何时读取:首次安装 XtQuant 或遇到安装问题时)
- 常见问题(何时读取:遇到常见问题时)
- 代码示例(何时读取:需要参考完整代码示例时)
- 更新日志(何时读取:查看版本更新历史时)
- xtdata Market Module API (When to read: Need to check market data interfaces)
- xtdata Market Data Fields and Data Dictionary (When to read: Need to check market data fields and data dictionary)
- xttrader Trading Module API (When to read: Need to check trading interfaces and data structure descriptions)
- Installation and Download Guide (When to read: First-time installation of XtQuant or encountering installation issues)
- FAQs (When to read: Encountering common issues)
- Code Examples (When to read: Need to refer to complete code examples)
- Changelog (When to read: Check version update history)
注意事项
Notes
环境要求
Environment Requirements
- 必须运行 MiniQMT:xttrader 交易模块需要 MiniQMT 客户端在后台运行
- 路径配置:确保 路径正确,否则连接会失败
userdata_mini - 行情订阅限制:单股订阅建议不超过 50 只,较多时建议使用全推数据
- Must Run MiniQMT: The xttrader trading module requires the MiniQMT client to run in the background
- Path Configuration: Ensure the path is correct, otherwise the connection will fail
userdata_mini - Market Subscription Limits: It is recommended not to subscribe to more than 50 individual stocks; use full push data when subscribing to more
数据获取注意
Data Acquisition Notes
- 数据补下载:历史数据需先通过 下载
download_history_data2 - 权限限制:Level2 数据需要终端有相应权限
- 时间格式:K线时间参数格式为 或
'20240101''20240101000000'
- Data Supplementary Download: Historical data must be downloaded first via
download_history_data2 - Permission Restrictions: Level2 data requires corresponding terminal permissions
- Time Format: K-line time parameters are in the format or
'20240101''20240101000000'
交易注意
Trading Notes
- 账号格式:股票账号直接使用资金账号字符串,期货账号需指定
'FUTURE' - 委托数量:股票以"股"为单位,债券以"张"为单位,期货以"手"为单位
- 订单编号:下单成功后返回正整数 order_id,-1 表示失败
- 异步操作:交易操作支持同步/异步两种模式,异步模式需配合回调使用
- Account Format: Use the capital account string directly for stock accounts; specify for futures accounts
'FUTURE' - Order Quantity: Stocks are in "shares", bonds in "sheets", futures in "lots"
- Order ID: A positive integer order_id is returned upon successful order placement; -1 indicates failure
- Asynchronous Operations: Trading operations support both synchronous and asynchronous modes; asynchronous mode requires matching callbacks
性能优化
Performance Optimization
- 批量请求:多只股票数据建议使用 批量获取
get_market_data - 缓存利用:已订阅的数据会自动缓存,无需重复订阅
- 线程安全:xttrader 支持多策略,但需使用不同的 session_id
- Batch Requests: It is recommended to use to obtain data for multiple stocks in batches
get_market_data - Cache Utilization: Subscribed data is automatically cached, no need to subscribe repeatedly
- Thread Safety: xttrader supports multiple strategies, but different session_ids must be used