Close Navigation
Learn more about IBKR accounts
IBKR Market Data –  From Real-time Bars to Ticks

IBKR Market Data – From Real-time Bars to Ticks

Posted August 29, 2022
Jogi Narain
Atreyu Trading Services

See Part I for instructions to setup the development and trading environment and Part II for using IBKR historical data within Backtrader.

In this next section we look at various types of real-time data that we could use to run trading strategies.

5-Second Real-time Bars from IB

Real-time bars represent a price performance for a specific period. These periods could be as long as a day or as short as a second, depending on the purpose for which the bar is to be used. Daily bars are usually the most popular for analysis whereas shorter duration bars can be used for trading.

In the case of IBKR the TWS API can be used to fetch 5-second duration bar.

The example below creates an active subscription that will return a single bar in real time every five seconds that has the OHLC values over that period. Additionally, we are switching off the backfill of data from initial start to reconnect in case of connection disruption.

By default, what=TRADES To receive OHLC trade price trade count data in Volume, it is necessary to specify what=MIDPOINT if the midpoint price is required. (See https://interactivebrokers.github.io/tws-api/realtime_bars.html)

Note that the TestPrinter used in this example has been described in part 2 of this series.

Output

Top Of Book Market Data (Level I)

Using the TWS API, real time market data can also be requested for trading and analysis. This data is not tick-by-tick but consists of aggregated snapshots taken at intra-second intervals which differ depending on the type of instrument:

The most common tick types are delivered automatically after a successful market data request. Currently the default tick type is 233  (see available Tick Types, https://interactivebrokers.github.io/tws-api/tick_types.html)

Example

Output

Real-time Tick by Tick Data

In addition to the aggregated tick snapshots, IBKR also has true tick-by-tick data, but it comes with some limitations. Tick-by-tick data corresponds to the data shown in the TWS Time & Sales. The maximum number of simultaneous tick-by-tick subscriptions allowed for a user is determined by the limitations below.

Limitations – Additional symbol request can be purchased through a quote booster pack, each quote booster pack provides a 100 market data lines. There is a limit of 10 quote booster packs per account and rest of the market data lines are allocated using equity and commissions.

The “what=” must be set to the following BID_ASK (BidAsk), TRADES (Last), TRADES_ALL (AllLast), MIDPOINT (MidPoint), the default is TRADES if “what” is not set. TRADES_ALL has additional trade types such as combos, derivatives, and average price trades that are not included in TRADES.

Note in the example below “timeframe=bt.TimeFrame.Ticks” to select the tick-by-tick IBKR function.

Output

Stay tuned for the next installment in this series to learn how to transition to paper trading using live data.

Visit Atreyu Trading Services https://www.atreyutrading.com/ for additional insight on Backtrader.

Disclosure: Interactive Brokers

Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.

This material is from Atreyu Trading Services and is being posted with its permission. The views expressed in this material are solely those of the author and/or Atreyu Trading Services and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

Disclosure: API Examples Discussed

Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.

Disclosure: Order Types / TWS

The order types available through Interactive Brokers LLC's Trader Workstation are designed to help you limit your loss and/or lock in a profit. Market conditions and other factors may affect execution. In general, orders guarantee a fill or guarantee a price, but not both. In extreme market conditions, an order may either be executed at a different price than anticipated or may not be filled in the marketplace.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.