AlgoTraderAlgoTrader Documentation

Chapter 18. Market Data

18.1. Creation of Bars based on Ticks
18.2. Numeric Precision
18.3. Price normalization
18.4. Market Data Gap Checking
18.5. Generic Events
18.6. Generic Tick Events

AlgoTrader provides Market Data Interfaces with the following market data providers:

AlgoTrader allows having multiple market data interfaces active at the same time so market data received from different market data providers can be compared in real-time.

To enable either of those Market Data Interfaces the following two steps have to be executed:

  1. The correct Spring Profile has to be activated according to Section 25.1, “Starter Classes”

  2. For Bloomberg market-data-bb and for InteractiveBrokers market-data-ib has to be added to the VM argument server-engine.init when running the AlgoTrader server.

Market Data Events itself are available in different types:

As the following diagram shows, market data providers deliver Price Events (TradeVO, BidVO & AskVO) or individual TickVO Fields.

In back testing AlgoTrader supports both Ticks or Bars. In both live trading and back testing Price events and Tick events can be aggregated into Bar events

Market Data Event Types

Figure 18.1. Market Data Event Types

Inside each strategy the MarketDataCacheService keeps a copy of the last MarketDataEvent for each Security. For further details see Section 7.2.16, “Market Data Cache Service”.

In both Simulation and Live Trading, Bars can be generated from Ticks or Price Events through the use of Esper Statements: use the time_batch to create bars:

  first(last) as open,
  max(last) as high,
  min(last) as low,
  last(last) as close
from min)
group by

and expr_batch for constant volume bars:

  max(last) as high,
  min(last) as low,
  first(last) as open,
  last(last) as close
from > 1000)
group by

In General different Securities are traded with different numeric precision (e.g. S&P Futures prices are two digits, whereas FX prices are usually 5-6 digits and crypto currencies are up to 8 digits). To accommodate different numeric precisions, AlgoTrader provides the following fields inside the class SecurityFamily:

Price normalization comes into play when multiple market data and/or trading adapters are in use that use different price multipliers / contract sizes for the same instrument. For example one adapter might quote prices in dollars with a contract size of 10 where as another one might quote them in cents with a contract size of 1000. The default contract size will be stored in the security_family table with all other cases (i.e. exceptions) stored using the broker_parameters table.

Since a continuous data feed of market data is essential for most trading strategies, AlgoTrader contains a feature that automatically warns if no market data has been received for a prolonged period of time. For this purpose the class SecurityFamily has a property maxGap, that defines the maximum number of minutes allowed without any market data updates. This is enforced by the CHECK_SECURITY_TICK_GAPS statement which can be turned on by changing the following property inside Alternatively the properties can be changed via Section 2.3, “VM Arguments”

# enables security tick gap check
statement.securityTickGap = true

Crypto currency exchanges are typically using web sockets to deliver market data. Web socket connections are typically not very stable and it can happen that a web socket connection disconnects or suddenly stops receiving data. For this purpose AlgoTrader has a feature that automatically reconnects the corresponding adapter if no market data has been received for a prolonged period of time. This is enforced by the CHECK_ADAPTER_TICK_GAP statement which can be turned on by changing the following property inside Alternatively the properties can be changed via Section 2.3, “VM Arguments”

# enables adapter tick gap check
statement.adapterTickGap = true

In addition to MarketDataEvents (i.e. TickVOs and BarVOs) there are general purpose Generic Events that can contain any type of information (e.g. virtual market data, signals, exposure values, etc.). In contrary to MarketDataEvents, which are sent from the AlgoTrader Server to subscribed strategies, these Generic Events are sent from one strategy to one or more receiving strategies. A Generic Event class has to subclass GenericEventVO. Subscription to Generic Events is based on the class of the Generic Event.

Example: To subscribe to a Generic Event of type Signal (which is a subclass of GenericEventVO), the following needs to be done:


To send a GenericEvent, use the following method:

getEventDispatcher().broadcast(signal, EventRecipient.REMOTE_ONLY);

GenericEvents are automatically propagated to the Strategy Esper Engine where they can be accessed as follows (the event type Signal needs to be added to the Esper config file):

select * from Signal;

In addition it is possible to handle incoming GenericEvents through the onGenericEvents method:


public void onGenericEvent(GenericEventVO event) {

It is also possible to feed Generic Events via CSV Files in Simulation Mode. To enable this, the following property inside has to be updated. Alternatively the properties can be changed via Section 2.3, “VM Arguments”

# should generic events be feed
dataSource.feedGenericEvents = true

The file name of the CSV File has to be according to this schema:


  • className is the fully qualified class name (e.g. ch.algotrader.event.Signal)

  • rank is the sort order for situations where there are multiple GenericEvent types for the same time stamp

In contrast to Section 18.5, “Generic Events” the system also provides Generic Tick Events (class GenericTickVO). A Generic Tick Event represents additional price information on a particular instrument made available by market data providers (e.g. open price, close price, vwap price).

As GenericTickVO is a subclass of MarketDataEventVO a strategy will automatically gen Generic Tick Events delivered when it has subscribed to the corresponding instrument.

A Generic Tick has a TickType which can be one of OPEN, HIGH, LOW, CLOSE, OPEN_INTEREST, IMBALANCE or VWAP. A Generic Tick Event can hold either a BigDecimal, Double or Integer value.