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

Andre Zege azege at yahoo.com
Fri Aug 20 22:39:05 CEST 2010


I actually took down previous version of the post -- i made a small error
there and was not clear about my question. Let me repeat as in original post
my thanks to the guys giving advice and help and special gratitude to Jeff
-- thanks to his post i "almost" understand IBrokers, i think :). 

The code that Jeff posted works and fast with liquid stocks. However, with
thinly traded stocks, that don't have much volume code hangs because
callbacks checks for NAs in a group of stocks. I first circumvented this by
introducing clock counter in the callback that returns data no matter
whether NAs are present after certain number of seconds elapsed after
entering callback, but in the end i didn't like this hack, although it
worked for practical purposes. As it turned out, thinly traded stocks
returned quotes, it's just volume info that was missing. So, i modified
Jeffs eWrapper.data to include only quotes and quote sizes and it basically
flies. Too fast in fact, as API complains about exceeding limit of 50
requests for second. 



However, there is a problem i haven't figured out yet. Let me illustrate
using Jeffs code

st<-c("AAPL", "MSFT", "C", "INTC", "BAC", "GE", "F")
reqMktData(tws, lapply(st[1:4],twsSTK),
eventWrapper=eWrapper.data(4),CALLBACK=snapShot

returns

2 -1 2104 Market data farm connection is OK:cashfarm 
2 -1 2104 Market data farm connection is OK:usfarm 
     BidSize BidPrice AskPrice AskSize   Last LastSize  Volume
AAPL       5   249.94   249.99       2 249.94        4  134468
MSFT       6    24.21    24.23       5  24.23       10  488292
C       6468     3.75     3.76    2934   3.75        1 5165088
INTC      87    18.84    18.88      98  18.85        1  943913


Great. Now i try the rest 3 stocks

reqMktData(tws, lapply(st[5:7],twsSTK),
eventWrapper=eWrapper.data(3),CALLBACK=snapShot)

I unexpectedly get the following error

Error in `*tmp*`[[id]] : subscript out of bounds


This would happen every time my second chunk of stocks is smaller than the
largest of the previous chunks.
If i try to get quotes for 4 or more stocks instead of 3 everything is fine.
For example, i can run all stocks at the same time fine

 354 Requested market data is not subscribed. 
2 1 300 Can't find EId with tickerId:1 
2 2 354 Requested market data is not subscribed. 
2 2 300 Can't find EId with tickerId:2 
2 3 354 Requested market data is not subscribed. 
2 3 300 Can't find EId with tickerId:3 
     BidSize BidPrice AskPrice AskSize   Last LastSize  Volume
AAPL       1   249.92   249.95       8 249.95       10  134670
MSFT       6    24.23    24.26      16  24.24        9  489790
C       7448     3.75     3.76    4340   3.76       10 5169998
INTC      14    18.84    18.85      34  18.85        6  945219
BAC      451    12.88    12.90      33  12.89       19 1628480
GE        27    15.00    15.03       2  15.03     2064  646974
F         15    11.77    11.77      48  11.77       10  503978


Got some weird messages, but the data is here. Now if i attempt to repeat
the call i started with, 

 reqMktData(tws, lapply(st[1:4],twsSTK),
eventWrapper=eWrapper.data(4),CALLBACK=snapShot)

i get familiar error

Error in `*tmp*`[[id]] : subscript out of bounds

Somehow, the size of structure allocated for data is getting stuck
somewhere, but i cannot figure out where. Can someone help?


-- 
View this message in context: http://r.789695.n4.nabble.com/how-to-get-quotes-with-IBrokers-tp2329328p2333008.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list