[R-SIG-Finance] New IBrokers package on CRAN

Jeff Ryan jeff.a.ryan at gmail.com
Sun Feb 24 22:01:36 CET 2008


Hi Adrian,

I probably should have made it version 0.0-0001 :)

I didn't mention in the docs - but you need to have the TWS
configured as you would for any client:

Configure => Api => All Api settings:

1) Add 127.0.0.1 to 'Trusted IP addresses'
2) Make sure that Enable ActiveX and Socket Clients is checked.

I think since the error checking is currently non-existent, something
must be get messed up
in the delay.

The first thing to the TWS in the connection is '37', which I think is
the client version # as far as the TWS is concerned.  I am very new to
this whole socket programming thing, so your patience is much
appreciated.

see twsConnect

I am running under Mac OSX at the moment, though I also have a Solaris
box.  No windows ones unfortunately to test yet.  One of these days
I'll have to break down and buy one :)

Trades and Account are probably quite easy to add.  I wrote it mostly
to fetch historical data, along the lines of RBloomberg, less the 20k
subscription fee :)

Mutlithreading is probably not even possible, at least not in the
traditional sense, from what I can tell of R's socket mechanisms.

I think the roadmap will be:

get it mostly bug free for data requests - those being
reqHistoricalData, reqMktData, and maybe a way to grab RT bars for a
set period.  Then add basic non-data methods.  From there _maybe_ look
into orders/etc.  But I seriously doubt the current native R code
implementation could handle that well.  I will probably look into a
C/C++ interface to get that done.

Anyway give a try per the above suggestions:  I just ran this myself:

> library(IBrokers)
Loading required package: xts
Loading required package: zoo
IBrokers version 0.0-1: (pre-alpha)
See ?IBrokers for details
> tws <- twsConnect()
> reqCurrentTime(tws)
[1] 1203885994
> dia <- reqHistoricalData(tws,twsEquity("DIA","SMART","ISLAND"))
> head(dia)
                     Open   High    Low  Close Volume    WAP hasGaps Count
2008-01-24 06:00:00 122.90 123.92 122.26 123.45 193868 123.07       0 48447
2008-01-25 06:00:00 124.63 124.71 121.72 122.19 194009 123.15       0 43732
2008-01-28 06:00:00 122.02 123.82 121.00 123.59 162384 122.36       0 37939
2008-01-29 06:00:00 124.21 124.90 123.34 124.56 146030 124.28       0 33402
2008-01-30 06:00:00 124.21 126.68 123.46 123.79 208275 125.05       0 44105
2008-01-31 06:00:00 122.68 126.90 122.41 126.10 212845 124.80       0 47008
>


On Sun, Feb 24, 2008 at 2:22 PM, Adrian Dragulescu <adrian_d at eskimo.com> wrote:
>
>  Jeff,
>
>  Many thanks for putting together this package.  It should be very useful.
>
>  I am having trouble using it.  I know it's 0.0-1, but I would like to
>  start using it.  I have R 2.6.2, latest IB Workstation and latest API
>  9.40.  I use WinXP.
>
>  > require(IBrokers)
>  Loading required package: IBrokers
>  Loading required package: xts
>  Loading required package: zoo
>  IBrokers version 0.0-1: (pre-alpha)
>  See ?IBrokers for details
>  > con <- twsConnect()
>  Error in readChar(s, 1) : negative length vectors are not allowed
>  >
>
>  An IB window pops up and asks me if I want to accept incoming connection.
>  I press yes (but the error in the R GUI is already there).
>
>  If I try to understand where the error comes from:
>  > s <- socketConnection(port = 7496)
>  > s
>        description              class               mode
>  text             opened
>  "->localhost:7496"           "socket"               "a+"
>  "text"           "opened"
>           can read          can write
>              "yes"              "yes"
>  > writeChar(as.character("1"), s)
>  > (curChar <- readChar(s, 1))
>
>  Another IB window pops up informing me that "The Socket client is out of
>  date and needs to be upgraded." And R GUI hangs up using 99% CPU.
>
>  Any suggestions are much appreciated.
>
>  In terms of the package wishlist, it would be nice to have access to the
>  Trades window and the Account window.
>
>  Adrian Dragulescu
>
>  I tried doing hooking R to IB using their Java API and got something
>  very rudimentary going on, but my Java wasn't that good to figure out how
>  to handle the multithreading features.
>
>
>
>
>
>
>
>  On Fri, 22 Feb 2008, Jeff Ryan wrote:
>
>  > R-Sig-Finance:
>  >
>  > I'd like to announce the alpha version of a new package IBrokers:
>  >
>  > Designed to provide native R access to Interactive Brokers' trading
>  > platform, it is currently in a very alpha stage.  I am releasing at
>  > this early stage it to gauge interest and feedback as to which API
>  > features should be considered priority.
>  >
>  > It is working, though very little error checking (read: none) is done
>  > at present.  I will be updating this aggressively.
>  >
>  > ?IBrokers
>  >
>  > R API to the Interactive Brokers Trader Workstation (TWS).
>  >
>  > Description:
>  >
>  >      A very limited R implementation of the TWS API.  At present it is
>  >      only able to access historic data from the Interactive Brokers
>  >      servers. Future additions will include more API access and
>  >      possible real-time charting via the 'quantmod' package.
>  >
>  >      A word of warning.  I wrote this in 3 days.  Much of the current
>  >      event loop is being rewritten/rethought to better handle errors, add
>  >      some sort of callback mechanism, as well as
>  >      speed up large data requests.  This version is mostly a
>  >      proof-of-concept and will be updated regularly.  That said, please
>  >      report any and all bugs/experiences to the maintainer so they can
>  >      be incorporated into development versions.
>  >
>  >      **DO NOT USE in an R session that you can't afford to lose!**
>  >
>  > Details:
>  >
>  >
>  >        Package:  IBrokers
>  >        Type:     Package
>  >        Version:  0.0-1
>  >        Date:     2008-02-21
>  >        License:  GPL-3
>  >
>  >      The current API methods supported are:
>  >
>  >      reqCurrentTime: The TWS server time in seconds since the epoch
>  >      reqHistoricalData: Fetch historical data
>  >
>  > Author(s):
>  >
>  >      Jeffrey A. Ryan
>  >
>  >      Maintainer: Jeffrey A. Ryan <jeff.a.ryan at gmail.com>
>  >
>  > References:
>  >
>  >      Interactive Brokers: <URL: www.interactivebrokers.com>
>  >
>  > --
>  > There's a way to do it better - find it.
>  > Thomas A. Edison
>  >
>
>
> > _______________________________________________
>  > R-SIG-Finance at stat.math.ethz.ch mailing list
>  > https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>  > -- Subscriber-posting only.
>  > -- If you want to post, subscribe first.
>  >
>



-- 
There's a way to do it better - find it.
Thomas A. Edison



More information about the R-SIG-Finance mailing list