softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

reqHistoricalData error with certain symbols #113

Closed ajdore closed 3 years ago

ajdore commented 3 years ago

Having an error with SPY when I run the historical data demo code (other symbols work fine).

                  % create an empty stock contract
                  contract = com.ib.client.Contract();
                  contract.symbol('SPY')
                  contract.exchange('SMART');
                  contract.primaryExch('ARCA');
                  contract.currency('USD');
                  contract.secType('STK');

                    % request historical data for our contract for a year w/ 1-day bars
                    session.eClientSocket.reqHistoricalData(1000001,contract,'20141230 16:00:00','1 Y','1 day','TRADES',1,1,false,[]); pause(0.5);

returns this error

                  1000001 162 Historical Market Data Service error message:Delayed market data query for ARCA STK

                  Error using HistoricalDataExample (line 37)
                  Java exception occurred:
                  org.apache.commons.collections.BufferUnderflowException: The buffer is already empty

                      at org.apache.commons.collections.buffer.BoundedFifoBuffer.get(BoundedFifoBuffer.java:261)

However, the same request for AGG returns fine (AGG has the same contract details as SPY).

ajdore commented 3 years ago

Looks like the issue was related to data limitations on the IB end.

softwarespartan commented 3 years ago

The exception is related to calling get method when the buffer is empty. It’s not very idiomatic of matlab to do that so it generally confuses everyone. The easy work around is to just check if buf.size > 0 then e=buf.get(). And, as you mentioned, the buffer is empty because of a data limitation for the exchange on IB side which is usually determined by the data subscriptions for the IB account.