-1

I'm working with the TWS API and it's not working for me. I got it close to doing what I want to do, but I am stuck trying to figure out how to use the lapply function correctly.

Here's what I got to work currently:

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

I would like to make specifications to the twsSTK in the above. Without using lapply, a single

library("IBrokers")
tws <- twsConnect()
reqMktData(tws, twsSTK("AAPL", exch = "ISLAND", currency = "USD"), tickGenerics="", snapshot=T)
twsDisconnect(tws)

However, I am having trouble trying to adequately use lapply in this case.

Does anyone know how to deal with lapply here?

Matthew Lundberg
  • 42,009
  • 6
  • 90
  • 112
Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60

1 Answers1

0

I read the documentation on lapply incorrectly. See attached for my solution.

library("IBrokers")
tws <- twsConnect()
tickers <- c("AAPL","YHOO","MSFT","GLD")
reqMktData(tws, lapply(tickers, twsSTK, exch = "ISLAND", currency = "USD"), tickGenerics="", snapshot=T)
twsDisconnect(tws)
Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60