• 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.

  • client.reqMatchingSymbols(211, "IB");
  • client.reqMatchingSymbols(211, "IB");
  • client.reqMatchingSymbols(202, "IB")
  • m_pClient->reqMatchingSymbols(11001, "IBM");
  • 1  self.reqMatchingSymbols(212, "IB")

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}",
    contractDescription.Contract.ConId, contractDescription.Contract.Symbol, contractDescription.Contract.SecType,
    contractDescription.Contract.PrimaryExch, contractDescription.Contract.Currency, derivSecTypes);
    }
    }
  • @Override
    public void symbolSamples(int reqId, ContractDescription[] contractDescriptions) {
    System.out.println("Contract Descriptions. Request: " + reqId + "\n");
    for (ContractDescription cd : contractDescriptions) {
    Contract c = cd.contract();
    StringBuilder derivativeSecTypesSB = new StringBuilder();
    for (String str : cd.derivativeSecTypes()) {
    derivativeSecTypesSB.append(str);
    derivativeSecTypesSB.append(",");
    }
    System.out.print("Contract. ConId: " + c.conid() + ", Symbol: " + c.symbol() + ", SecType: " + c.secType() +
    ", PrimaryExch: " + c.primaryExch() + ", Currency: " + c.currency() +
    ", DerivativeSecTypes:[" + derivativeSecTypesSB.toString() + "]");
    }
    System.out.println();
    }
  • 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)
    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): %ld %s %s %s %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("\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 += derivSecType
    10  derivSecTypes += " "
    11  print("Contract: conId:%s, symbol:%s, secType:%s primExchange:%s, currency:%s, derivativeSecTypes:%s" % (
    12  contractDescription.contract.conId,
    13  contractDescription.contract.symbol,
    14  contractDescription.contract.secType,
    15  contractDescription.contract.primaryExchange,
    16  contractDescription.contract.currency, derivSecTypes))
    17