IBrokers - reqMktData results in error saying ticker is "ambiguous"

3k views Asked by At

I'm trying to snap real time market data using IBrokers API on R.

For an odd reason, Microsoft (MSFT) doesn't work.

For example, this works:

library("IBrokers")
tws <- twsConnect()
nms <- c("AAPL","YHOO")
reqMktData(tws, lapply(nms, twsSTK), tickGenerics="", snapshot=T)
twsDisconnect(tws)

However, this doesn't work:

library("IBrokers")
tws <- twsConnect()
nms <- c("AAPL","YHOO","MSFT")
reqMktData(tws, lapply(nms, twsSTK), tickGenerics="", snapshot=T)
twsDisconnect(tws)

The error message is below:

2 3 200 The contract description specified for MSFT is ambiguous. 

However, this isn't an ambiguous ticker, and is on the same exchange as YHOO and AAPL.

Does anyone know what I need to do to get around this issue? Thank you.

3

There are 3 answers

0
Trexion Kameha On BEST ANSWER

To get around this I simply specified the stock exchange for separate tickers that trade ambiguously on nasdaq.

tickers_nasdaq<-c("MSFT","INTC","CSCO")
reqMktData(tws, lapply(tickers_nasdaq, twsSTK, exch = "SMART", primary="NASDAQ", currency = "USD"), tickGenerics="", snapshot=T)

Obviously this isn't ideal, but at least it works.

1
Pedro Lobito On

Later answer...
You shouldn't specify the primary exchange because you'll have problems with other symbols, instead, specify the m_localSymbol on your contract() to the same value as the m_symbol, in this case: MSFT

https://www.interactivebrokers.com/en/software/api/apiguide/java/contract.htm

0
misantroop On

There are a couple of ways to do this:

  1. Request contract details with both symbol and currency defined. Use the received Contract object going forward. This works for 99.9% of cases, only exceptions would be symbols that trade on different exchanges simultaneously AND have the same currency, this is possible for names listed in London for example where they trade using foreign currencies.

  2. Catch the ambiguous error in your handler and resend again by trying all the primaryExchanges one by one (NYSE, NASDAQ, BATS, ARCA etc).

  3. Build an internal dict or key-value pair of equities with their corresponding exchanges.