[R-SIG-Finance] how to get quotes with IBrokers

R P Herrold herrold at owlriver.com
Wed Aug 18 06:57:06 CEST 2010

On Tue, 17 Aug 2010, zerdna wrote:

> Hi, i need to get a quotes for a large set of stocks at 5 min after the open.
> I am trying to use IBrokers, but frankly not making much progress. I
> understand that i need to use reqMktData.

> i get a dataframe back after waiting for a while -- about 12 sec per ticker,
> which comes out to more than 1.5 hours for my list of 500 tickers. Also,
> most of the data is NA. Maybe it has to do with stocks on the list being
> relatively illiquid or maybe i am doing something wrong. Could someone
> comment, please?

That 12 sec has me suspicious, as that is hte data rate limit 
for history, and not market data detail.  that said, lets work 
the numbers

one would use a history query, perhaps if you have a 
constraint that all of the data should cover the same time 
interval. You could query for just market open + 5 min. 
There is a rate limitation there of 60 such queries over a ten 
minute measurement interval (and so 500 symbols will take a 
bit under 90 minutes -- viz., the hour and a half mentioned 
We have demonstrated such from time to time, and include the 
needed scripts for doing such in our releases

If all you seek is a simple tick snapshot over a short time 
interval, you should be able to parallelize the queries in 
batches somewhat more quickly, at the cost of having differing 
time frames for the compiled data.  A person is permitted a 
hundred active market detail lines At any time (absent having 
higher caps as a higher commission customer -- see IB's 
documentation).  Another constrant you must observe the '50 
requests per second' rate limitation. So I would design a set 
up and cancel of 25 symbols per second, probably in four ranks 
of 25 (perhaps five ranks of 20 to avoid pushing limits) and 
letting a request stay active at least 3 (or 4) seconds to get 

Every 5 seconds you'll get 100 done, and so in about 25 
seconds, you should have market data for all in your universe. 
As you say the detail is sparce on thinly traded instruments, 
this simply may not be long enough for an actual trade to 
cross and to be reported, and so my first mention of using 
history sampling may well provide a better solution

I've not published an example harvesting 'tick' (Market Data) 
information for a while, nor rolling through ranks of symbol 
sets, but these are straightforward and as I recall we ship an 
example script on this

It is not clear that 'driving' R and IBrokers at these rates 
is doable -- perhaps Jeff Ryan can comment from experience. 
Certainly we are able to get these rates from our tool, the 
details of which are out of scope here.  We mention the matter 
some time ago here

raising our concern about the mismatch between a sync 
'request' control under R with limited error interception and 
threading models, and async responsive 'messages' flows from 
the TWS

-- Russ herrold

More information about the R-SIG-Finance mailing list