
本方案由EasyQuant AI量化助手提供。如有更多问题直接用EasyQuant AI量化助手帮您快速解决量化交易编程难题。问题背景QMT 策略在下单前常需要获取股票名称、上市日期、涨跌停价、最小价格变动单位等基础信息。get_instrument_detail()可返回单个股票、ETF、期货或期权合约的详细信息。完整代码示例from xtquant import xtdata STOCK_CODE 000001.SZ def main(): # iscompleteTrue 获取完整字段 detail xtdata.get_instrument_detail( STOCK_CODE, iscompleteTrue ) if detail is None: print(未获取到合约信息请检查证券代码) return print( 基础信息 ) print(证券代码, detail.get(InstrumentID)) print(证券名称, detail.get(InstrumentName)) print(交易所, detail.get(ExchangeID)) print(统一代码, detail.get(UniCode)) print(上市日期, detail.get(OpenDate)) print(到期/退市日期, detail.get(ExpireDate)) print(\n 交易价格信息 ) print(涨停价, detail.get(UpStopPrice)) print(跌停价, detail.get(DownStopPrice)) print(最小价格变动, detail.get(PriceTick)) # 适合下单前进行涨跌停检查 up_limit detail.get(UpStopPrice) down_limit detail.get(DownStopPrice) if up_limit is not None and down_limit is not None: print( \n当前允许报价区间%.2f ~ %.2f % (down_limit, up_limit) ) if __name__ __main__: main()下单前价格校验示例def is_valid_order_price(stock_code, order_price): detail xtdata.get_instrument_detail( stock_code, iscompleteTrue ) if detail is None: return False up_limit detail.get(UpStopPrice) down_limit detail.get(DownStopPrice) if up_limit is None or down_limit is None: return False return down_limit order_price up_limit注意事项证券代码格式通常为000001.SZ、600000.SH。找不到标的时接口可能返回None代码中必须处理。涨跌停价只适合做报价边界校验不代表以该价格下单一定能成交。不同品种返回字段可能存在差异建议使用dict.get()安全读取。总结get_instrument_detail()是 QMT 下单前校验与合约信息读取的重要接口可用于涨跌停价格检查、期货合约信息识别和策略参数适配。本方案由EasyQuant AI量化助手提供。