miniqmt

Original🇨🇳 Chinese
Translated
5 scriptsChecked / no sensitive code detected

MiniQMT Xuntou Quantitative Trading Interface, based on the XtQuant Python library, supports market data acquisition (K-line, tick data, financial data, etc.) and trading operations (order placement, order cancellation, querying assets/orders/positions) for A-shares, futures, and options. It is used when users need to obtain real-time/historical market data from MiniQMT, conduct quantitative trading, or perform backtesting.

21installs
Added on

NPX Install

npx skill4agent add lzwme/finance-quant-skills miniqmt

Tags

Translated version includes tags in frontmatter

SKILL.md Content (Chinese)

View Translation Comparison →

MiniQMT Quantitative Trading Skill

Task Objectives

  • 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 Environment Requirements

  • 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
    userdata_mini
    path under the MiniQMT installation directory is used for xttrader connection

Directory Structure

QMT安装目录\
├── bin.x64\XtMiniQmt.exe # MiniQMT 主程序
├── userdata_mini\        # 用户数据目录(xttrader 连接路径)
│   ├── xqtrader.ini      # 交易配置
│   └── xtdatacenter.ini  # 行情配置

Core Concepts

Security Code Format

  • Stocks: 6-digit number + market suffix, e.g.,
    600000.SH
    (Shanghai),
    000001.SZ
    (Shenzhen)
  • Futures: Product code + contract month, e.g.,
    rb2405.SF
    (Rebar)
  • Options: Underlying code + exercise month, e.g.,
    510050.SH
    (SSE 50 ETF Option)

Period Type (period)

PeriodDescriptionPeriodDescription
tick
Tick data
1q
Quarterly line
1m
1-minute line
1hy
Semi-annual line
5m
5-minute line
1y
Annual line
15m
15-minute line
1w
Weekly line
30m
30-minute line
1d
Daily line
1h
1-hour line
1mon
Monthly line

Dividend Adjustment Type (dividend_type)

  • none
    - No adjustment
  • front
    - Forward adjustment
  • back
    - Backward adjustment
  • front_ratio
    - Equal ratio forward adjustment
  • back_ratio
    - Equal ratio backward adjustment

Trading Market (market)

MarketConstantMarketConstant
Shanghai
xtconstant.SH_MARKET
CFFEX
xtconstant.MARKET_ENUM_INDEX_FUTURE
Shenzhen
xtconstant.SZ_MARKET
SHFE
xtconstant.MARKET_ENUM_SHANGHAI_FUTURE
Beijing Stock Exchange
xtconstant.MARKET_ENUM_BEIJING
CZCE
xtconstant.MARKET_ENUM_ZHENGZHOU_FUTURE
DCE
xtconstant.MARKET_ENUM_DALIANG_FUTURE
GFEX
xtconstant.MARKET_ENUM_GUANGZHOU_FUTURE

Account Type (account_type)

TypeConstantTypeConstant
Stock
xtconstant.SECURITY_ACCOUNT
Shanghai-Hong Kong Stock Connect
xtconstant.HUGANGTONG_ACCOUNT
Futures
xtconstant.FUTURE_ACCOUNT
Shenzhen-Hong Kong Stock Connect
xtconstant.SHENGANGTONG_ACCOUNT
Margin
xtconstant.CREDIT_ACCOUNT
Futures Option
xtconstant.FUTURE_OPTION_ACCOUNT
Stock Option
xtconstant.STOCK_OPTION_ACCOUNT
--

Operation Steps

  1. Confirm Requirements — Identify whether it is market data acquisition or trading operation
  2. Select Module — Use xtdata for market data, xttrader for trading
  3. Call Script — Select the corresponding script based on data type
  4. Parse Results — The agent analyzes the returned JSON format data

Intent Recognition Mapping Examples

User QueryCorresponding FunctionCalling Method
"贵州茅台实时股价"Real-time market snapshotxtdata.get_full_tick
"平安银行K线数据"K-line dataxtdata.get_market_data
"招商银行财务指标"Financial statementsxtdata.get_financial_data
"半导体板块成分股"Sector constituent stocksxtdata.get_stock_list_in_sector
"今日可转债信息"ETF/convertible bond dataxtdata.get_cb_info
"新股申购"IPO informationxtdata.get_ipo_info
"下单买入平安银行"Trading order placementxttrader.order_stock
"查询持仓"Position queryxttrader.query_stock_positions
"撤单"Order cancellationxttrader.cancel_order_stock

Usage Examples

Example 1: Get Real-time Stock Market Data

python
import xtdata

# 获取全推行情快照
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()

Example 2: Get Historical K-line Data

python
import xtdata

# 下载历史K线数据
xtdata.download_history_data2(['600519.SH'], period='1d', start_time='')

# 获取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'
)

Example 3: Trading Order Placement

python
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)

# 创建账号对象
acc = StockAccount('1000000365')  # 替换为实际账号

# 连接交易
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'
)

# 查询资产
asset = xt_trader.query_stock_asset(acc)
print(f"可用资金: {asset.cash}")

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']}")

# 订阅多只股票
xtdata.subscribe_whole_quote(['SH', 'SZ'], callback=on_tick_data)
xtdata.run()

Resource Index

Market Data Scripts

  • 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

  • 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

  • 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 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

  • Must Run MiniQMT: The xttrader trading module requires the MiniQMT client to run in the background
  • Path Configuration: Ensure the
    userdata_mini
    path is correct, otherwise the connection will fail
  • 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

  • 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
    '20240101'
    or
    '20240101000000'

Trading Notes

  • Account Format: Use the capital account string directly for stock accounts; specify
    'FUTURE'
    for futures accounts
  • 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

  • Batch Requests: It is recommended to use
    get_market_data
    to obtain data for multiple stocks in batches
  • 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