In an effort to download data from IB into R I have followed the steps here: IBrokers request Historical Futures Contract Data?. Which are about the same as here: https://cran.r-project.org/web/packages/IBrokers/vignettes/IBrokers.pdf.
It all works. With one exception: reqHistoricalData
does not work with expired months. Running the following code gives error message: "Warning message: In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106, : No security definition has been found for the request"
#DOES NOT WORK (using expired month)
tws <- twsConnect()
mydata <- reqHistoricalData(tws, twsFuture("ES","GLOBEX","201603"), barSize='1 min', duration='5 D', useRTH='0', whatToShow='TRADES')
#YET THE FOLLOWING DO WORK (using unexpired months)
mydata <- reqHistoricalData(tws, twsFuture("ES","GLOBEX","201606"), barSize='1 min', duration='5 D', useRTH='0', whatToShow='TRADES')
mydata <- reqHistoricalData(tws, twsFuture("ES","GLOBEX","201609"), barSize='1 min', duration='5 D', useRTH='0', whatToShow='TRADES')
getContract("ES_M6")
The IB FAQ says the following on that message: "Why do I receive an error 200 - No security definition has been found for the request when I call reqContractDetails, reqMktData, or addOrder() for a stock contract? When using these methods for a stock contract, leave Global Symbol and Trading Class blank." (found at https://www.interactivebrokers.com/en/software/api/apiguide/tables/frequentlyaskedquestions.htm)
Would greatly appreciate any insight into this. Thank you.