[R-SIG-Finance] [R-sig-finance] Fwd: Question on multiple sessions...

Jeff Ryan jeff.a.ryan at gmail.com
Thu Feb 12 17:04:02 CET 2009


Within the context of IBrokers, the entire process of collecting data and
acting upon it can take place within one session.

The notion of needing this to be multi-threaded isn't quite accurate, at
least by my figuring.

I am working on a paper/tutorial to outline this whole process, but here is
what I have found to work.

R is single threaded.  The approach I initially envisioned did involve some
sort of dual R-process, where communication was via a file or sockets.  This
obviously wasn't ideal, but seemed workable.

Turns out that with sockets, *blocking* sockets in R are the only
reliable/efficient cross-platform mechanism to communicate that I have found
while keeping everything in R.  This causes some interesting problems if you
are waiting for messages from another process, and those messages are
irregular in time.  Essentially you are just shifting the issue from one
single-threaded process into two.  Same problems persist.

So, a quick primer on how IBrokers can manage this.

A request for data is sent via reqMktData.  The connection then blocks until
a message is received back from Interactive Brokers.  This is in the form of
a continuous stream of messages.  At each iteration/call of readBin [where
new messages are taken from the socket] the proper handling via callbacks
take place.

In the CRAN version I have two methods available to the user. One is where
custom handlers for each _type_ of data can be passed into the original
reqMktData call, e.g. on each new bid message that arrives, do *something*. 
The other original approach was to use a custom CALLBACK argument to manage
the entire message stream.

The CALLBACK basically handles _all_ possible messages, and with custom
action based on what is happening.

The newest version at  http://ibrokers.googlecode.com
http://ibrokers.googlecode.com  has a much better interface.  This new
version allows for a user defined actions to take place at each new message
(essentially a global level of processing), and within each different type
of message received.  By using special eWrapper closures you can enable data
to persist from one message to another, all in memory, all within one
session.

The obvious caveat here is that everything is non-interactive.  Which at
first glance seems a bit strange given most interaction with R is
interactive, but from an automated strategy perspective is just fine.

Again, I am working on some solid documentation related to IBrokers
specifically, but will also be publishing a white-paper on the general idea
of real-time processing in the near future at  http://www.insightalgo.com
http://www.insightalgo.com .

Jeff


I will be making a paper/presentation available with more details at some
point in the near future 

Vince Fulco wrote:
> 
> Assuming one wants to use an open session to collect real time data a
> la IBrokers or similar, what would be the best way to maintain another
> session for calculations?  Is RServe the answer or is there a lighter
> solution for semi-auto analytical script running?  Either Windows or
> Linux solutions would be appreciated.  TIA
> 
> 
> Vince Fulco, CFA, CAIA
> 612.424.5477 (universal)
> vfulco1 at gmail.com
> 
> _______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Fwd%3A-Question-on-multiple-sessions...-tp21966670p21979004.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list