• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Receiving exchange components

A single data request from the API can receive aggregate quotes from multiple exchanges. With API versions 9.72.18 and TWS 9.62 and higher, the tick types 'bidExch' (tick type 32), 'askExch' (tick type 33), 'lastExch' (tick type 84) are used to identify the source of a quote. To preserve bandwidth, the data returned to these tick types consists of a sequence of capital letters rather than a long list of exchange names for every returned exchange name field. To find the full exchange name corresponding to a single letter code returned in tick types 32, 33, or 84, and API function IBApi::EClient::reqSmartComponents is available.

Different IB contracts have a different exchange map containing the set of exchanges on which they trade. Each exchange map has a different code, such as "a6" or "a9". This exchange mapping code is returned to IBApi::EWrapper::tickReqParams immediately after a market data request is made by a user with market data subscriptions. To find a particular map of single letter codes to full exchange names, the function reqSmartComponents is invoked with the exchange mapping code returned to tickReqParams.

  • client.reqSmartComponents(13002, testImpl.BboExchange);
  • client.reqSmartComponents(1013, "a6");
  • client.reqSmartComponents(13002, wrapperImpl.BboExchange)
  • m_pClient->reqSmartComponents(13002, m_bboExchange);
  • 1  # Requests description of map of single letter exchange codes to full exchange names
    2  self.reqSmartComponents(1013, "a6")

For instance, a market data request for the IBKR US contract may return the exchange mapping identifier "a6" to tickReqParams. Invoking the function reqSmartComponents with the symbol "a9" will reveal the list of exchanges offering market data for the IBKR US contract, and their single letter codes. The code for "ARCA" may be "P". In that case if "P" is returned to the exchange tick types, that would indicate the quote was provided by ARCA.

  • public void smartComponents(int reqId, Dictionary<int, KeyValuePair<string, char>> theMap)
    {
    StringBuilder sb = new StringBuilder();
    sb.AppendFormat("==== Smart Components Begin (total={0}) reqId = {1} ====\n", theMap.Count, reqId);
    foreach (var item in theMap)
    {
    sb.AppendFormat("bit number: {0}, exchange: {1}, exchange letter: {2}\n", item.Key, item.Value.Key, item.Value.Value);
    }
    sb.AppendFormat("==== Smart Components Begin (total={0}) reqId = {1} ====\n", theMap.Count, reqId);
    Console.WriteLine(sb);
    }
  • @Override
    public void smartComponents(int reqId, Map<Integer, SimpleEntry<String, Character>> theMap) {
    System.out.println("smart components req id:" + reqId);
    for (Map.Entry<Integer, SimpleEntry<String, Character>> item : theMap.entrySet()) {
    System.out.println("bit number: " + item.getKey() +
    ", exchange: " + item.getValue().getKey() + ", exchange letter: " + item.getValue().getValue());
    }
    }
  • Public Sub smartComponents(reqId As Integer, theMap As Dictionary(Of Integer, KeyValuePair(Of String, Char))) Implements EWrapper.smartComponents
    Dim sb As New StringBuilder
    sb.AppendFormat("==== Smart Components Begin (total={0}) reqId = {1} ===={2}", theMap.Count, reqId, Environment.NewLine)
    For Each item In theMap
    sb.AppendFormat("bit number: {0}, exchange: {1}, exchange letter: {2}{3}", item.Key, item.Value.Key, item.Value.Value, Environment.NewLine)
    Next
    sb.AppendFormat("==== Smart Components Begin (total={0}) reqId = {1} ===={2}", theMap.Count, reqId, Environment.NewLine)
    Console.WriteLine(sb)
    End Sub
  • void TestCppClient::smartComponents(int reqId, SmartComponentsMap theMap) {
    printf("Smart components: (%u):\n", theMap.size());
    for (SmartComponentsMap::iterator i = theMap.begin(); i != theMap.end(); i++) {
    printf(" bit number: %d exchange: %s exchange letter: %c\n", i->first, std::get<0>(i->second).c_str(), std::get<1>(i->second));
    }
    }
  • 1  def smartComponents(self, reqId:int, map:SmartComponentMap):
    2  super().smartComponents(reqId, map)
    3  print("smartComponents: ")
    4  for exch in map:
    5  print(exch.bitNumber, ", Exchange Name: ", exch.exchange, ", Letter: ", exch.exchangeLetter)