I am using matlab and interactive brokers API. I am getting real time data using

tickerID = ib.realtime({ct},'233',@(varargin)ibEventRealTimeData(varargin{:}));

where ib is the interface to interactive brokers TWS Activex object and ct is the contract.

I am getting all the events (ticksize, tickprice and so on) but I can't aggregate data/prices (for example, in 5 minute bars). What am I missing?


  • $\begingroup$ What do you mean by "I can't aggregate"? Any error message? $\endgroup$
    – dkhokhlov
    Commented Jun 29, 2015 at 18:37
  • $\begingroup$ If you've got tick data, can't you just generate quantized data using, e.g., the time series object? $\endgroup$ Commented Jun 30, 2015 at 5:08
  • $\begingroup$ Hi Wisentgenus. I mean something similar to the data provided by this example, but in real time: d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype) requests Interactive Brokers aggregated intraday data for a specific type of market data tick ticktype. $\endgroup$ Commented Jul 3, 2015 at 10:58
  • $\begingroup$ DMitri, could you please give me a hint on how do that? $\endgroup$ Commented Jul 3, 2015 at 10:58

2 Answers 2


Here is a pure Java library with Matlab examples for getting daily and minute aggregated bars. It is based on IB Java API. I wrapped it to have a simple interface:


IB has limitations when requesting historical data:

  • Making identical historical data requests within 15 seconds.
  • Making six or more historical data requests for the same Contract, Exchange and Tick Type within two seconds.
  • Do not make more than 60 historical data requests in any ten-minute period.

In order to aggregate the 5-min bars, you need to add code within your ibEventRealTimeData function that remembers the previous values (possibly using a global or persistent variable) and appends the new data to it.

If you do not need realtime info, you could make a single request for 5-min historical data. But here too, IB sends the results in separate events that you would need to aggregate within your callback.

As an alternative you could use the IB-Matlab product, which connects IB and Matlab, and aggregates the information for you, in both the historical/intra-day request and the realtime bars request.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.