5

如何从 Interactive Brokers 将 INDEX 的历史数据导入 R?如果是期货,我会使用这个命令(正如IBrokers request Historical Futures Contract Data?在这里所建议的那样):

library(twsInstrument)
a <- reqHistoricalData(tws, getContract("ESJUN2013"))

connid但是标准普尔指数的相应命令给出了一个错误:

> a <- reqHistoricalData(tws, getContract("11004968"))
Connected with clientId 110.
Contract details request complete. Disconnected.
waiting for TWS reply on ES ....failed.
Warning message:
In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106,  :
  Error validating request:-'uc' : cause - HMDS Expired Contract Violation:contract can not expire.

PS 有足够积分的人应该为 IBrokers 创建一个标签

4

2 回答 2

5

我没有对指数数据的市场数据访问权限,但我认为以下应该可行。

reqHistoricalData(tws, twsIndex(symbol = "SPX", exch = "CBOE"))
## waiting for TWS reply on SPX ....failed.
## NULL

## Warning message:
## In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106,  :
##  Historical Market Data Service error message:No market data permissions for CBOE IND

以下是reqContractDetails使用与上述类似方法的结果,证明合约对象是由twsIndex

reqContractDetails(tws, twsIndex(symbol = "SPX", exch = "CBOE"))
## [[1]]
## List of 18
##  $ version       : chr "8"
##  $ contract      :List of 16
##   ..$ conId          : chr "416904"
##   ..$ symbol         : chr "SPX"
##   ..$ sectype        : chr "IND"
##   ..$ exch           : chr "CBOE"
##   ..$ primary        : chr ""
##   ..$ expiry         : chr ""
##   ..$ strike         : chr "0"
##   ..$ currency       : chr "USD"
##   ..$ right          : chr ""
##   ..$ local          : chr "SPX"
##   ..$ multiplier     : chr ""
##   ..$ combo_legs_desc: chr ""
##   ..$ comboleg       : chr ""
##   ..$ include_expired: chr ""
##   ..$ secIdType      : chr ""
##   ..$ secId          : chr ""
##   ..- attr(*, "class")= chr "twsContract"
##  $ marketName    : chr "SPX"
##  $ tradingClass  : chr "SPX"
##  $ conId         : chr "416904"
##  $ minTick       : chr "0.01"
##  $ orderTypes    : chr [1:22] "ACTIVETIM" "ADJUST" "ALERT" "ALLOC" ...
##  $ validExchanges: chr "CBOE"
##  $ priceMagnifier: chr "1"
##  $ underConId    : chr "0"
##  $ longName      : chr "S&P 500 Stock Index"
##  $ contractMonth : chr ""
##  $ industry      : chr "Indices"
##  $ category      : chr "Broad Range Equity Index"
##  $ subcategory   : chr "*"
##  $ timeZoneId    : chr "CST"
##  $ tradingHours  : chr "20130321:0830-1500;20130322:0830-1500"
##  $ liquidHours   : chr "20130321:0830-1500;20130322:0830-1500"
## 
于 2013-03-21T10:20:43.237 回答
0

一个如何请求非美国股票的合约信息,我尝试了下面的两个调用,我在合约详细信息中收到错误,但这些是两种证券的符号和交换,我可以在 TWS 中为它们提取信息。

reqContractDetails(tws, twsEquity(symbol = "BMW", exch = "IBIS"))

reqContractDetails(tws, twsEquity(symbol = "BP", exch = "EBS"))

我什至尝试使用 exch='SMART' 但它对 BMW 失败并为 BP 获取 NYSE 行。这个电话只针对美股吗?

于 2015-06-08T13:59:07.210 回答