Component Exchanges

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. Note: This function can only be used when the exchange is open.

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

** Python **

# Requests description of map of single letter exchange codes to full exchange names
self.reqSmartComponents(1018, "a6")

** Java **

client.reqSmartComponents(1013, "a6");

For instance, a market data request for the IBKR US contract may return the exchange mapping identifier "a6" to IBApi.EWrapper.tickReqParams . Invoking the function IBApi.EClient.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.

** Python **

def smartComponents(self, reqId:int, smartComponentMap:SmartComponentMap):
    super().smartComponents(reqId, smartComponentMap)
    for smartComponent in smartComponentMap:
        print("SmartComponent.", smartComponent)

** Java **

public void smartComponents(int reqId, Map<Integer, Entry<String, Character>> theMap) {
    System.out.println("smart components req id:" + reqId);

    for (Map.Entry<Integer, Entry<String, Character>> item : theMap.entrySet()) {
        System.out.println("bit number: " + item.getKey() + 
                ", exchange: " + item.getValue().getKey() + ", exchange letter: " + item.getValue().getValue());