Skip to content
Prev 5657 / 15274 Next

Howto cancel reqMktData() from IBrokers package?

Hi Mark,

The basic premise is that the eWrapper is just the collection of
callbacks that manage each incoming message.  Either doing nothing
with it, yet still processing correctly [eWrapper(NULL)], or handling
each message type with some particular logic.

It seems like you have extended that perfectly.

What you need to customize is the CALLBACK that is passed in.  By
default this is twsCALLBACK.

In a nutshell, this is the main 'loop' that waits on the connection or
connections you have established to the TWS or external data source,
and it cycles though each new incoming message.  The messages
themselves are handled by the eWrapper object's callback(s) you
write/use.

What you want to do is add a few lines of code in a new CALLBACK that
test for the condition of the data you are storing (some n number of
bars, or all values are now non-NA, etc), and when it evaluates to
TRUE, simply return() from the call.  Easiest is just make a copy of
the twsCALLBACK and modify.

The function itself (reqMktData) should cancel the outstanding data
subscription you made, but to be sure you can also call cancelMktData
yourself.

I'll be giving a tutorial on trading with IBrokers (and event
processing in general with R) at the upcoming R/Finance 2010
conference in Chicago this coming April 16 and 17.

http://www.RinFinance.com

If you can't make the conference or the workshop, the slides will
eventually make their way to the website.

Hope that helps,
Jeff
On Fri, Feb 19, 2010 at 12:34 PM, Mark Breman <breman.mark at gmail.com> wrote: