• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Requesting Contract Details

Complete details about a contract in IB's database can be retrieved using the function IBApi.EClient.reqContractDetails. This includes information about a contracts conID, symbol, local symbol, currency, etc. which is returned in a IBApi.ContractDetails object IBApi.EWrapper.contractDetail. reqContractDetails takes as an argument a Contract object which may uniquely match an argument, 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 IBApi::EWrapper::contractDetails.

Note: 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.

Request for Bond details will be returned to IBApi::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.

One particular use of the IBApi::EClient::reqContractDetails function is to request an option chain. See Option Chains for more details.

BroadTape News List

The example below shows an "incomplete" news IBApi.Contract with no symbol or currency defined. In most cases using such a contract would result in an invalid contract details error since a symbol or localSymbol is required. IBApi.EClient.reqContractDetails will instead use it to obtain the whole BroadTape news chain from the TWS.

  • Contract contract = new Contract();
    contract.SecType = "NEWS";
    contract.Exchange = "BRF"; //Briefing Trader
    ...
    client.reqContractDetails(211, ContractSamples.NewsFeedForQuery());
  • Contract contract = new Contract();
    contract.secType("NEWS");
    contract.exchange("BRF"); //Briefing Trader
    ...
    client.reqContractDetails(211, ContractSamples.NewsFeedForQuery());
  • Dim contract As Contract = New Contract()
    contract.SecType = "NEWS"
    contract.Exchange = "BRF" 'Briefing Trader
    ...
    client.reqContractDetails(211, ContractSamples.NewsFeedForQuery())
  • Contract contract;
    contract.secType = "NEWS";
    contract.exchange = "BRF"; //Briefing Trader
    ...
    m_pClient->reqContractDetails(211, ContractSamples::NewsFeedForQuery());
  • 1  contract = Contract()
    2  contract.secType = "NEWS"
    3  contract.exchange = "BRFG" #Briefing Trader
    ...
    1  self.reqContractDetails(10004, ContractSamples.NewsFeedForQuery())

All returned objects will be delivered via IBApi.EWrapper.contractDetails. Once all contracts have been delivered the IBApi.EWrapper.contractDetailsEnd marker will be triggered to notify it.

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void contractDetails(int reqId, ContractDetails contractDetails)
    {
    Console.WriteLine("ContractDetails begin. ReqId: " + reqId);
    printContractMsg(contractDetails.Contract);
    printContractDetailsMsg(contractDetails);
    Console.WriteLine("ContractDetails end. ReqId: " + reqId);
    }
    ...
    public virtual void contractDetailsEnd(int reqId)
    {
    Console.WriteLine("ContractDetailsEnd. "+reqId+"\n");
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void contractDetails(int reqId, ContractDetails contractDetails) {
    System.out.println(EWrapperMsgGenerator.contractDetails(reqId, contractDetails));
    }
    ...
    @Override
    public void contractDetailsEnd(int reqId) {
    System.out.println("ContractDetailsEnd. "+reqId+"\n");
    }
  • Public Class EWrapperImpl
    Implements EWrapper
    ...
    Public Sub contractDetails(reqId As Integer, contractDetails As IBApi.ContractDetails) Implements IBApi.EWrapper.contractDetails
    Console.WriteLine("ContractDetails begin. ReqId: " & reqId)
    printContractMsg(contractDetails.Contract)
    printContractDetailsMsg(contractDetails)
    Console.WriteLine("ContractDetails end. ReqId: " & reqId)
    End Sub
    ...
    Public Sub contractDetailsEnd(reqId As Integer) Implements IBApi.EWrapper.contractDetailsEnd
    Console.WriteLine("ContractDetailsEnd - ReqId [" & reqId & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::contractDetails( int reqId, const ContractDetails& contractDetails) {
    printf( "ContractDetails begin. ReqId: %d\n", reqId);
    printContractMsg(contractDetails.contract);
    printContractDetailsMsg(contractDetails);
    printf( "ContractDetails end. ReqId: %d\n", reqId);
    }
    ...
    void TestCppClient::contractDetailsEnd( int reqId) {
    printf( "ContractDetailsEnd. %d\n", reqId);
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def contractDetails(self, reqId: int, contractDetails: ContractDetails):
    2  super().contractDetails(reqId, contractDetails)
    3  printinstance(contractDetails)
    ...
    1  def contractDetailsEnd(self, reqId: int):
    2  super().contractDetailsEnd(reqId)
    3  print("ContractDetailsEnd. ReqId:", reqId)

Important: due to the potentially high amount of data resulting from such queries this request is subject to pacing. Although a request such as the above one will be answered immediately, a similar subsequent one will be kept on hold for one minute. This amount of time will increase if more such requests are performed. To prevent this narrow down the amount of eligible contracts by providing an expiration date specifying at least the year (i.e. 2016) or the year and the month (i.e. 201603 for March 2016).