Trexion Kameha Trexion Kameha - 1 month ago 18
R Question

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

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.

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.