• C#
  • Java
  • VB
  • C++
  • Python
Contact us
5 Second Real Time Bars

Real time and historical data functionality is combined through the IBApi.EClient.reqRealTimeBars request. reqRealTimeBars will create an active subscription that will return a single bar in real time every five seconds that has the OHLC values over that period. reqRealTimeBars can only be used with a bar size of 5 seconds.

Important: real time bars subscriptions combine the limitations of both, top and historical market data. Make sure you observe Market Data Lines and Pacing Violations for Small Bars (30 secs or less). For example, no more than 60 *new* requests for real time bars can be made in 10 minutes, and the total number of active active subscriptions of all types cannot exceed the maximum allowed market data lines for the user.

Requesting

  • client.reqRealTimeBars(3001, ContractSamples.EurGbpFx(), 5, "MIDPOINT", true, null);
  • client.reqRealTimeBars(3001, ContractSamples.EurGbpFx(), 5, "MIDPOINT", true, null);
  • client.reqRealTimeBars(3001, ContractSamples.EurGbpFx(), 5, "MIDPOINT", True, Nothing)
  • m_pClient->reqRealTimeBars(3001, ContractSamples::EurGbpFx(), 5, "MIDPOINT", true, TagValueListSPtr());
  • 1  self.reqRealTimeBars(3001, ContractSamples.EurGbpFx(), 5, "MIDPOINT", True, [])
  • To receive volume, VWAP, or trade count data, it is necessary to specify whatToShow as TRADES.
  • It may be necessary to remake real time bars subscriptions after the IB server reset or between trading sessions.

Receiving

Once invoked, historical data bars of five seconds will start being delivered through the IBApi.EWrapper.realtimeBar callback:

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void realtimeBar(int reqId, long time, double open, double high, double low, double close, long volume, double WAP, int count)
    {
    Console.WriteLine("RealTimeBars. " + reqId + " - Time: " + time + ", Open: " + open + ", High: " + high + ", Low: " + low + ", Close: " + close + ", Volume: " + volume + ", Count: " + count + ", WAP: " + WAP);
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void realtimeBar(int reqId, long time, double open, double high,
    double low, double close, long volume, double wap, int count) {
    System.out.println("RealTimeBars. " + reqId + " - Time: " + time + ", Open: " + open + ", High: " + high + ", Low: " + low + ", Close: " + close + ", Volume: " + volume + ", Count: " + count + ", WAP: " + wap);
    }
  • Public Class EWrapperImpl
    Implements EWrapper
    ...
    Public Sub realtimeBar(reqId As Integer, time As Long, open As Double, high As Double, low As Double, close As Double, volume As Long, WAP As Double, count As Integer) Implements IBApi.EWrapper.realtimeBar
    Console.WriteLine("RealTimeBars. " & reqId & " - Time: " & time & ", Open: " & open & ", High: " & high & ", Low: " & low & ", Close: " &
    close & ", Volume: " & volume & ", Count: " & count & ", WAP: " & WAP)
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::realtimeBar(TickerId reqId, long time, double open, double high, double low, double close,
    long volume, double wap, int count) {
    printf( "RealTimeBars. %ld - Time: %ld, Open: %g, High: %g, Low: %g, Close: %g, Volume: %ld, Count: %d, WAP: %g\n", reqId, time, open, high, low, close, volume, count, wap);
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def realtimeBar(self, reqId: TickerId, time:int, open_: float, high: float, low: float, close: float,
    2  volume: int, wap: float, count: int):
    3  super().realtimeBar(reqId, time, open_, high, low, close, volume, wap, count)
    4  print("RealTimeBar. TickerId:", reqId, RealTimeBar(time, -1, open_, high, low, close, volume, wap, count))

-Volume for US stocks has a multiplier of 100

Canceling

To cancel an active request simply invoke IBApi.EClient.cancelRealTimeBars

  • client.cancelRealTimeBars(3001);
  • client.cancelRealTimeBars(3001);
  • client.cancelRealTimeBars(3001)
  • m_pClient->cancelRealTimeBars(3001);
  • 1  self.cancelRealTimeBars(3001)