• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Stock Contract Search

Starting in API v973.02 and TWS v964, a function IBApi::EClient::reqMatchingSymbols is available to search for stock contracts. The input can be either the first few letters of the ticker symbol, or for longer strings, a character sequence matching a word in the security name. For instance to search for the stock symbol 'IBKR', the input 'I' or 'IB' can be used, as well as the word 'Interactive'. Up to 16 matching results are returned.

  • There must be an interval of at least 1 second between successive calls to reqMatchingSymbols
  • client.reqMatchingSymbols(211, "IBM");
  • client.reqMatchingSymbols(211, "IB");
  • client.reqMatchingSymbols(218, "IBM")
  • m_pClient->reqMatchingSymbols(11001, "IBM");
  • 1  self.reqMatchingSymbols(218, "IBM")

Matching stock contracts are returned to IBApi::EWrapper::symbolSamples with information about types of derivative contracts which exist (warrants, options, dutch warrants, futures).

  • public void symbolSamples(int reqId, ContractDescription[] contractDescriptions)
    {
    string derivSecTypes;
    Console.WriteLine("Symbol Samples. Request Id: {0}", reqId);
    foreach (var contractDescription in contractDescriptions)
    {
    derivSecTypes = "";
    foreach (var derivSecType in contractDescription.DerivativeSecTypes)
    {
    derivSecTypes += derivSecType;
    derivSecTypes += " ";
    }
    Console.WriteLine("Contract: conId - {0}, symbol - {1}, secType - {2}, primExchange - {3}, currency - {4}, derivativeSecTypes - {5}, description - {6}, issuerId - {7}",
    contractDescription.Contract.ConId, contractDescription.Contract.Symbol, contractDescription.Contract.SecType,
    contractDescription.Contract.PrimaryExch, contractDescription.Contract.Currency, derivSecTypes, contractDescription.Contract.Description, contractDescription.Contract.IssuerId);
    }
    }
  • @Override
    public void symbolSamples(int reqId, ContractDescription[] contractDescriptions) {
    System.out.println(EWrapperMsgGenerator.symbolSamples(reqId, contractDescriptions));
    }
  • Public Sub symbolSamples(reqId As Integer, contractDescriptions As ContractDescription()) Implements EWrapper.symbolSamples
    Dim derivSecTypes As String
    Console.WriteLine("Symbol Samples. Request Id: " & reqId)
    For Each contractDescription In contractDescriptions
    derivSecTypes = ""
    For Each derivSecType In contractDescription.DerivativeSecTypes
    derivSecTypes += derivSecType
    derivSecTypes += " "
    Next
    Console.WriteLine("Contract conId: " & contractDescription.Contract.ConId & ", symbol: " & contractDescription.Contract.Symbol &
    ", secType: " & contractDescription.Contract.SecType & ", primExchange: " & contractDescription.Contract.PrimaryExch &
    ", currency: " & contractDescription.Contract.Currency & ", derivativeSecTypes: " & derivSecTypes &
    ", description: " & contractDescription.Contract.Description & ", issuerId: " & contractDescription.Contract.IssuerId)
    Next
    End Sub
  • void TestCppClient::symbolSamples(int reqId, const std::vector<ContractDescription> &contractDescriptions) {
    printf("Symbol Samples (total=%lu) reqId: %d\n", contractDescriptions.size(), reqId);
    for (unsigned int i = 0; i < contractDescriptions.size(); i++) {
    Contract contract = contractDescriptions[i].contract;
    std::vector<std::string> derivativeSecTypes = contractDescriptions[i].derivativeSecTypes;
    printf("Contract (%u): conId: %ld, symbol: %s, secType: %s, primaryExchange: %s, currency: %s, ", i, contract.conId, contract.symbol.c_str(), contract.secType.c_str(), contract.primaryExchange.c_str(), contract.currency.c_str());
    printf("Derivative Sec-types (%lu):", derivativeSecTypes.size());
    for (unsigned int j = 0; j < derivativeSecTypes.size(); j++) {
    printf(" %s", derivativeSecTypes[j].c_str());
    }
    printf(", description: %s, issuerId: %s", contract.description.c_str(), contract.issuerId.c_str());
    printf("\n");
    }
    }
  • 1  def symbolSamples(self, reqId: int,
    2  contractDescriptions: ListOfContractDescription):
    3  super().symbolSamples(reqId, contractDescriptions)
    4  print("Symbol Samples. Request Id: ", reqId)
    5 
    6  for contractDescription in contractDescriptions:
    7  derivSecTypes = ""
    8  for derivSecType in contractDescription.derivativeSecTypes:
    9  derivSecTypes += " "
    10  derivSecTypes += derivSecType
    11  print("Contract: conId:%s, symbol:%s, secType:%s primExchange:%s, "
    12  "currency:%s, derivativeSecTypes:%s, description:%s, issuerId:%s" % (
    13  contractDescription.contract.conId,
    14  contractDescription.contract.symbol,
    15  contractDescription.contract.secType,
    16  contractDescription.contract.primaryExchange,
    17  contractDescription.contract.currency, derivSecTypes,
    18  contractDescription.contract.description,
    19  contractDescription.contract.issuerId))