if (FALSE) {
tws <- twsConnect()
reqContractDetails(tws, twsEquity("QQQQ"))
# retrieve all QQQQ contracts as a list
reqContractDetails(tws, twsOption(local="", right="", symbol="QQQQ"))
# retrieve only calls
reqContractDetails(tws, twsOption(local="", right="C", symbol="QQQQ"))
# retrieve only puts
reqContractDetails(tws, twsOption(local="", right="P", symbol="QQQQ"))
opt.details <- lapply(c("MSFT","AAPL"),
function(x) {
reqContractDetails(tws,
twsOption(local="", right="",
symbol=x))
} )
length(opt.details) #number of symbols passed e.g. 2
sapply(opt.details, length) # contracts per symbol
}
Run the code above in your browser using DataLab