Contract 类参考
Contract 是 TWS API Reference 中的一个数据结构。本页按 IBKR TWS API Python 包 10.47.1 的字段核对,用中文解释常见用途。
合约对象,用来告诉 TWS 你要查询或交易哪个金融工具。股票、期权、期货、外汇、组合合约都通过它表达。
常见使用位置
Section titled “常见使用位置”reqContractDetails()、reqMktData()、reqHistoricalData()、placeOrder()、reqExecutions() 等接口都会用到。
| 字段 | 类型 | 中文解释 |
|---|---|---|
conId | int | IBKR 合约 ID。它是最稳定的合约标识之一,建议先通过合约详情查询确认。 |
symbol | str | 合约代码,例如 AAPL、ES、EUR。 |
secType | str | 证券类型,例如 STK、OPT、FUT、CASH、BAG。 |
lastTradeDateOrContractMonth | str | 最后交易日或合约月份。期权/期货常用,股票通常留空。 |
lastTradeDate | str | 最后交易日。新版字段多使用 lastTradeDateOrContractMonth。 |
strike | float | 期权或其他衍生品行权价。 |
right | str | 期权方向,常见值为 C / CALL 或 P / PUT。 |
multiplier | str | 合约乘数,例如美股期权通常是 100。 |
exchange | str | 交易所或路由目的地。股票常用 SMART 路由,但 primaryExchange 不应写 SMART。 |
primaryExchange | str | 主上市交易所,用来消除股票歧义;不要填 SMART。 |
currency | str | 交易币种,例如 USD、HKD、EUR。 |
localSymbol | str | IBKR 本地合约符号。期权、期货、外汇和部分海外品种经常需要它来避免歧义。 |
tradingClass | str | 交易类别。期权、期货和部分交易所品种经常需要。 |
includeExpired | bool | 是否包含已过期合约。期货历史数据可能需要,但股票通常保持 False。 |
secIdType | str | 证券标识类型,常见值包括 ISIN、CUSIP、SEDOL、RIC。 |
secId | str | 证券标识值,例如 ISIN、CUSIP、SEDOL、RIC 对应的具体编号。 |
description | str | 合约描述,通常由 TWS 返回。 |
issuerId | str | 编号字段。用于把请求、订单、合约或成交关联起来。 |
comboLegsDescrip | str | TWS 返回的组合腿文字描述,通常用于显示,不建议靠它反向解析交易逻辑。 |
comboLegs | list | 组合合约腿列表,每条腿是一个 ComboLeg。 |
deltaNeutralContract | 对象 / 列表 / 未设置 | Delta-neutral 合约对象,通常用于期权组合或波动率订单。 |
- 股票常见写法是
symbol='AAPL'、secType='STK'、exchange='SMART'、currency='USD'。 primaryExchange用来消除歧义,不能写SMART。- 期权、期货、组合合约通常还需要
lastTradeDateOrContractMonth、strike、right、multiplier、tradingClass或localSymbol。
Python API 中对应源码文件为 ibapi/contract.py。不同语言的类名和字段名可能略有大小写差异,但核心含义一致;写策略时应以自己安装的 API 版本为准。