undefined

Stock Contract Search

Starting in API v973.02 and TWS v964, a function LYNXApi.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

** Python **

self.reqMatchingSymbols(211, "LYNX")

** Java **

client.reqMatchingSymbols(211, "LYNX");

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

** Python **

def symbolSamples(self, reqId: int,
    contractDescriptions: ListOfContractDescription):
    super().symbolSamples(reqId, contractDescriptions)
    print("Symbol Samples. Request Id: ", reqId)
    for contractDescription in contractDescriptions:
        derivSecTypes = ""
        for derivSecType in contractDescription.derivativeSecTypes:
            derivSecTypes += derivSecType
            derivSecTypes += " "

            print("Contract: conId:%s, symbol:%s, secType:%s primExchange:%s, ""currency:%s, derivativeSecTypes:%s" %
                  (contractDescription.contract.conId,
                   contractDescription.contract.symbol,
                   contractDescription.contract.secType,
                   contractDescription.contract.primaryExchange,
                   contractDescription.contract.currency, 
                   derivSecTypes))

** Java **

@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();
}