xtquant
XtQuant QMT Python SDK - 集成行情数据(xtdata)和交易接口(xttrade),支持A股、期货、期权等中国证券市场。
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/coderwpf/xtquantXtQuant(迅投QMT Python SDK)
XtQuant is the Python SDK for the QMT/miniQMT quantitative trading platform, developed by ThinkTrader (XunTou Technology). It contains two core modules:
- xtdata — Market Data Module: real-time quotes, historical K-lines, tick data, Level 2 data, financial data, sector management
- xttrade — Trading Module: order placement, position/order queries, account management, margin trading, futures/options, smart algorithms
⚠️ Requires miniQMT or QMT client running on Windows. XtQuant connects to the QMT process via local TCP. You need QMT/miniQMT access enabled by your broker.
安装
pip install xtquant
You can also download from the official website: http://dict.thinktrader.net/nativeApi/download_xtquant.html
架构概述
Your Python script (any IDE, any Python version)
↓ (xtquant SDK, pip install)
├── xtdata → miniQMT (market data service, TCP connection)
└── xttrade → miniQMT (trading service, TCP connection)
↓
Broker trading system
核心模块参考
| Module | Import | Purpose |
|---|---|---|
xtdata | from xtquant import xtdata | Market data: K-lines, tick, Level 2, financials, sectors |
xttrader | from xtquant.xttrader import XtQuantTrader | Trading: order placement, queries, callbacks |
xtconstant | from xtquant import xtconstant | Constants: order types, price types, market codes |
xttype | from xtquant.xttype import StockAccount | Account types: STOCK, CREDIT, FUTURE |
快速入门 — 行情数据
from xtquant import xtdata
# Connect to local miniQMT (default: localhost)
xtdata.connect()
# Download historical K-line data (must download to local cache before first access)
xtdata.download_history_data('000001.SZ', '1d', start_time='20240101', end_time='20240630')
# Get local K-line data (returns a dict of DataFrames keyed by stock code)
data = xtdata.get_market_data_ex(
[], # field_list, empty list means all fields
['000001.SZ'], # stock_list, list of stock codes
period='1d',
start_time='20240101',
end_time='20240630',
dividend_type='front' # 复权类型: none (unadjusted), front (forward-adjusted), back (backward-adjusted), front_ratio (proportional forward), back_ratio (proportional backward)
)
print(data['000001.SZ'])
实时行情订阅
def on_data(datas):
"""Quote data callback function, receives pushed real-time data"""
for stock_code, data in datas.items():
print(stock_code, data)
# Subscribe to tick data for a single stock
xtdata.subscribe_quote('000001.SZ', period='tick', callback=on_data)
# Subscribe to full-market quote push
xtdata.subscribe_whole_quote(['SH', 'SZ'], callback=on_data)
xtdata.run() # Block the current thread, continuously receiving callback data
财务数据
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-coderwpf-xtquant": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
backtrader
Backtrader 开源量化回测框架 - 支持多数据源、多策略、多周期回测与实盘交易,纯Python实现。
pywencai
同花顺问财自然语言数据查询工具 - 使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据。
tqsdk
天勤量化TqSdk - 开源Python期货/期权交易SDK,提供实时行情、回测和实盘交易功能。
rqalpha
RQAlpha 米筐开源事件驱动回测框架 - 支持A股和期货,模块化架构,可自由扩展。
baostock
BaoStock 免费A股数据平台 - 支持K线、财务数据、行业分类查询,无需注册即可使用。