Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBrokers Historical Index Data

Tags:

r

ibrokers

How do I get historical data of an INDEX into R from Interactive Brokers? If it were futures, I would use this command (as suggested here IBrokers request Historical Futures Contract Data?):

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

But the corresponding commanding with the connid of the S&P Index gives an error:

> 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.

P.S. Someone with enough points should create a tag for IBrokers

like image 934
mchangun Avatar asked Mar 21 '13 03:03

mchangun


1 Answers

I don't have market data access to index data, but I think following should work.

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

Following is result of reqContractDetails using similar approach as above which proves that the contract object is created properly by 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"
## 
like image 101
CHP Avatar answered Sep 28 '22 01:09

CHP