🚀 AI 一键生成 qmt 策略代码
立即体验

QMT 平台如何查询合约详细信息?get_instrumentdetail 字段对照表与 Python 示例

qmt | 发布时间: 2026/7/22
以下内容由 EasyQuant 生成。

问题描述

请根据以下 SEO 主题生成完整页面内容:

Title: qmt 获取合约属性:get_instrumentdetail 字段对照表

Question: qmt 怎么查询合约的流通股本、总股本和最小变价单位?

解决方案

QMT 获取合约属性:get_instrumentdetail 字段对照表

在 QMT 平台中,如果需要查询某个股票、期货或期权合约的详细属性(如流通股本总股本最小变价单位等),可以使用 ContextInfo.get_instrumentdetail(stockcode) 接口。该接口会返回一个包含合约所有静态属性的字典(dict)。


1. 核心接口介绍

ContextInfo.get_instrumentdetail()

  • 用法ContextInfo.get_instrumentdetail(stockcode)
  • 参数stockcode (string),股票或合约代码,例如 '600000.SH'
  • 返回:返回一个字典(dict),其中包含了该合约的详细信息。

对于您关心的三个指标,其对应的字典 Key 如下:

  • 流通股本FloatVolumn
  • 总股本TotalVolumn
  • 最小变价单位PriceTick

2. Python 代码示例

您可以在策略的 handlebarinit 函数中直接调用此接口。以下是一个完整的查询示例:

#coding:gbk

def init(ContextInfo):
    # 设定基础股票池
    ContextInfo.set_universe(['600000.SH'])

def handlebar(ContextInfo):
    # 仅在最后一根 K 线执行一次,避免重复打印
    if not ContextInfo.is_last_bar():
        return
        
    stock = '600000.SH'
    # 获取合约详细信息
    detail = ContextInfo.get_instrumentdetail(stock)
    
    if detail:
        # 提取流通股本、总股本和最小变价单位
        float_vol = detail.get('FloatVolumn', 0)  # 流通股本
        total_vol = detail.get('TotalVolumn', 0)  # 总股本
        price_tick = detail.get('PriceTick', 0)   # 最小变价单位
        name = detail.get('InstrumentName', '')
        
        print(f"合约代码: {stock} ({name})")
        print(f"流通股本: {float_vol} 股")
        print(f"总 股 本: {total_vol} 股")
        print(f"最小变价单位: {price_tick} 元")
    else:
        print(f"未能获取到 {stock} 的合约详细信息")

3. get_instrumentdetail 返回字典字段对照表

调用该接口返回的字典中包含丰富的合约属性,完整字段对照如下:

字段 Key 含义 适用类型
ExchangeID 合约市场代码 通用
InstrumentID 合约代码 通用
InstrumentName 合约名称 通用
ProductID 合约的品种ID 期货
ProductName 合约的品种名称 期货
CreateDate 上市日期 期货
OpenDate IPO日期 股票
ExpireDate 退市日或者到期日 通用
PreClose 前收盘价格 通用
SettlementPrice 前结算价格 通用
UpStopPrice 当日涨停价 通用
DownStopPrice 当日跌停价 通用
FloatVolumn 流通股本 股票
TotalVolumn 总股本 股票
LongMarginRatio 多头保证金率 期货
ShortMarginRatio 空头保证金率 期货
PriceTick 最小变价单位 通用
VolumeMultiple 合约乘数 (期货以外默认是1) 通用
MainContract 主力合约标记 期货
LastVolume 昨日持仓量 期货
InstrumentStatus 合约停牌状态 通用
IsTrading 合约是否可交易 通用
IsRecent 是否是近月合约 期货