Skip to navigation

Introduction

Complete details about a contract in IB’s database can be retrieved using the function EClient.reqContractDetails. This includes information about a contract’s conID, symbol, local symbol, currency, etc. which is returned in a ContractDetails object. reqContractDetails takes as an argument a Contract object which may uniquely match one contract, and unlike other API functions it can also take a Contract object which matches multiple contracts in IB’s database. When there are multiple matches, they will each be returned individually to the function EWrapper.contractDetails.

Request for Bond details will be returned to EWrapper.bondContractDetails instead. Because of bond market data license restrictions, there are only a few available fields to be returned in a bond contract description, namely the minTick, exchange, and short name.

Notes:

  • Invoking reqContractDetails with a Contract object which has currency = USD will only return US contracts, even if there are non-US instruments which have the USD currency.
  • Derivative contract requests are internally paced. Attempts to query Options, Warrants, or Futures Options must contain their maximum level of detail such as Symbol, SecType, Exchange, Currency, Strike, Right, LastTradeDateOrExpiration, and potentially TradingClass.

Another function of EClient.reqContractDetails is to request the trading schedule of an instrument via the TradingHours and LiquidHours fields. The corresponding timeZoneId field will then indicate the time zone for the trading schedule of the instrument. TWS sends these timeZoneId strings to the API from the schedule responses as-is, and may not exactly match the time zones displayed in the TWS contract description.

Possible timeZoneId values are:

  • Europe/Riga
  • Australia/NSW
  • Europe/Warsaw
  • US/Pacific
  • Europe/Tallinn
  • Japan
  • US/Eastern
  • Europe/London
  • Africa/Johannesburg
  • Israel
  • Europe/Vilnius
  • MET
  • Europe/Helsinki
  • US/Central
  • Europe/Budapest
  • Asia/Calcutta
  • Hongkong
  • Europe/Moscow
  • GMT

Request Contract Details

EClient.reqContractDetails(reqId, contract)

Upon requesting EClient.reqContractDetails, all contracts matching the requested Contract Object will be returned to EWrapper.contractDetails or EWrapper.bondContractDetails.

When reqContractDetails is called for STK using symbol security type, exchange, and currency, TWS caches the contract data internally. Future order submissions for these contracts utilizing contract ID and exchange combination utilize the cached values to expedite order transmission speeds.

reqId
int

Request identifier to track data.

contract
ContractDetails

The contract used as sample to query the available contracts. Typically contains at least the Symbol, SecType, Exchange, and Currency.


self.reqContractDetails(reqId, contract)

Receive Contract Details

EWrapper.contractDetails(reqId, contract)

Receives the full contract’s definitions. This method will return all contracts matching the request via EClient.reqContractDetails. For example, one can obtain the whole option chain with it.

reqId
int

Request identifier to track data.

contract
ContractDetails

Contains the full contract object contents including all information about a specific traded instrument.


def contractDetails(self, reqId: int, contractDetails: ContractDetails):
print(reqId, contractDetails)

EWrapper.contractDetailsEnd

EWrapper.contractDetailsEnd(reqId)

After all contracts matching the request were returned, this method will mark the end of their reception.

reqId
int

Request identifier to track data.

def contractDetailsEnd(self, reqId: int):
print("ContractDetailsEnd. ReqId:", reqId)

Receive Bond Details

EWrapper.bondContractDetails(reqId, contract)

Delivers the Bond contract data after this has been requested via reqContractDetails.

reqId
int

Request identifier to track data.

contract
ContractDetails

Contains the full contract object contents including all information about a specific traded instrument.


def bondContractDetails(self, reqId: int, contractDetails: ContractDetails):
printinstance(reqId, contractDetails)