IBKR Java API – Receiving Market Data

Articles From: Interactive Brokers
Website: Interactive Brokers


Java is an extremely popular programming language, so it is no surprise that it has been ranked #1 on the TIOBE Index. Its solid and fast performance enhances algo trading systems. IBKR API supports custom applications written in Java.

We provide sample files to get algo traders started in coding and backtesting using this robust technology and pairing it with our award-winning Trader Workstation (TWS) platform.

Let’ s take a quick look at how easy it is to request market data, an important component in backtesting trading algos.

First, download the sample routine in Java via the Testbed, and review the supplemental file ScannerSubscriptionSamples and ContractSamples.java. These sample routines demonstrate how one can code the contracts and order parameters in Java. For instance:

public class EWrapperImpl implements EWrapper {

public void tickPrice(int tickerId, int field, double price, TickAttrib attribs) {
System.out.println(“Tick Price. Ticker Id:”+tickerId+”, Field: “+field+”, Price: “+price+”, CanAutoExecute: “+ attribs.canAutoExecute() “, pastLimit: ” + attribs.pastLimit() + “, pre-open: ” + attribs.preOpen());

public void tickSize(int tickerId, int field, int size) {
System.out.println(“Tick Size. Ticker Id:” + tickerId + “, Field: ” + field + “, Size: ” + size);

The connection to TWS is supported via the above mentioned method IBApi.EWrapper. See the GitHub Reference Guide for more sample code on delivering market data and sending order information.

For additional syntax samples in this programming language, visit our Java API news section.

Disclosure: Interactive Brokers

The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. 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.

The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.