[R-SIG-Finance] Unable to get option historical data using IBrokers

Marc Delvaux mdelvaux at gmail.com
Sat Jun 12 19:49:42 CEST 2010

I am trying to use IBrokers to get historical data for options.  The
exact problem is the inability to figure how to construct a valid
contract or in general to construct a valid request for options
historical data

-          Working under windows, version 2.10.1
-          IBrokers reports version 0.2.7 (alpha)
-          TWS reports Build 906.2, Jun 10, 2010 6:27:24 PM
-          I am able to connect and download stock historical data

I tried to use both the local symbol found using the TWS contact
details and the contract ID, and playing with some function
parameters, but to no avail at this time.  I guess I just need one
small nudge to see what I do wrong, but currently I am poking in the
dark and would appreciate any help.  Example session below.

On a side topic, thank you Jeff for IBrokers, it is a tremendous
simpler way to get data in R than trying to use directly the IB API.


Marc Delvaux

R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

IBrokers version 0.2-7: (alpha)
Implementing API Version 9.62

This software comes with NO WARRANTY.  Not intended for production use!
See ?IBrokers for details
[Previously saved workspace restored]

> R.version
platform       i386-pc-mingw32
arch           i386
os             mingw32
system         i386, mingw32
major          2
minor          10.1
year           2009
month          12
day            14
svn rev        50720
language       R
version.string R version 2.10.1 (2009-12-14)
> library(IBrokers)
Loading required package: xts
Loading required package: zoo
> tws <- twsConnect()
> aapl <- reqHistoricalData(tws,twsSTK("AAPL"))
TWS Message: 2 -1 2104 Market data farm connection is OK:usopt
TWS Message: 2 -1 2104 Market data farm connection is OK:usfarm
TWS Message: 2 -1 2106 HMDS data farm connection is OK:ushmds2a
waiting for TWS reply ..... done.
> str(aapl)
An ‘xts’ object from 2010-05-13 to 2010-06-11 containing:
  Data: num [1:21, 1:8] 263 255 255 257 250 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:8] "AAPL.Open" "AAPL.High" "AAPL.Low" "AAPL.Close" ...
 - attr(*, "from")= chr "20100512  18:43:14"
 - attr(*, "to")= chr "20100612  18:43:14"
 - attr(*, "src")= chr "IB"
 - attr(*, "updated")= POSIXct[1:1], format: "2010-06-12 10:43:15.887"
  Indexed by objects of class: [POSIXt,POSIXct] TZ:
  xts Attributes:
List of 4
 $ from   : chr "20100512  18:43:14"
 $ to     : chr "20100612  18:43:14"
 $ src    : chr "IB"
 $ updated: POSIXct[1:1], format: "2010-06-12 10:43:15.887"
> nly_put <- reqHistoricalData(tws,twsOPT("NLY 100717P00017000"))
TWS Message: 2 1 366 No historical data query found for ticker id:1
waiting for TWS reply .....
Error: Unable to complete historical data request
In addition: Warning message:
In errorHandler(con, verbose, OK = c(165, 300, 366, 2104, 2106,  :
  No security definition has been found for the request.

More information about the R-SIG-Finance mailing list