为了将数据从 IB 下载到 RI,请遵循以下步骤:IBrokers 请求历史期货合约数据?. 与此处大致相同:https ://cran.r-project.org/web/packages/IBrokers/vignettes/IBrokers.pdf 。
这一切都有效。有一个例外:reqHistoricalData
不适用于过期的月份。运行以下代码会给出错误消息:“警告消息:在 errorHandler(con,verbose, OK = c(165, 300, 366, 2104, 2106, : No security definition has 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")
IB 常见问题解答关于该消息的内容如下:“为什么我收到错误 200 - 当我为股票合约调用 reqContractDetails、reqMktData 或 addOrder() 时,未找到请求的安全定义?当使用这些方法进行股票合约,将全球代码和交易类别留空。” (可在https://www.interactivebrokers.com/en/software/api/apiguide/tables/frequentlyaskedquestions.htm找到)
非常感谢对此的任何见解。谢谢你。