Data
The NautilusTrader platform provides a set of built-in data types specifically designed to represent a trading domain. These data types include:
OrderBookDelta
(L1/L2/L3): Represents the most granular order book updates.OrderBookDeltas
(L1/L2/L3): Batches multiple order book deltas for more efficient processing.OrderBookDepth10
: Aggregated order book snapshot (up to 10 levels per bid and ask side).QuoteTick
: Represents the best bid and ask prices along with their sizes at the top-of-book.TradeTick
: A single trade/match event between counterparties.Bar
: OHLCV (Open, High, Low, Close, Volume) bar/candle, aggregated using a specified aggregation method.InstrumentStatus
: An instrument-level status event.InstrumentClose
: The closing price of an instrument.
NautilusTrader is designed primarily to operate on granular order book data, providing the highest realism for execution simulations in backtesting. However, backtests can also be conducted on any of the supported market data types, depending on the desired simulation fidelity.
Order books
A high-performance order book implemented in Rust is available to maintain order book state based on provided data.
OrderBook
instances are maintained per instrument for both backtesting and live trading, with the following book types available:
L3_MBO
: Market by order (MBO) or L3 data, uses every order book event at every price level, keyed by order ID.L2_MBP
: Market by price (MBP) or L2 data, aggregates order book events by price level.L1_MBP
: Market by price (MBP) or L1 data, also known as best bid and offer (BBO), captures only top-level updates.
Top-of-book data, such as QuoteTick
, TradeTick
and Bar
, can also be used for backtesting, with markets operating on L1_MBP
book types.
Instruments
The following instrument definitions are available:
Betting
: Represents an instrument in a betting market.BinaryOption
: Represents a generic binary option instrument.Cfd
: Represents a Contract for Difference (CFD) instrument.Commodity
: Represents a commodity instrument in a spot/cash market.CryptoFuture
: Represents a deliverable futures contract instrument, with crypto assets as underlying and for settlement.CryptoPerpetual
: Represents a crypto perpetual futures contract instrument (a.k.a. perpetual swap).CurrencyPair
: Represents a generic currency pair instrument in a spot/cash market.Equity
: Represents a generic equity instrument.FuturesContract
: Represents a generic deliverable futures contract instrument.FuturesSpread
: Represents a generic deliverable futures spread instrument.Index
: Represents a generic index instrument.OptionContract
: Represents a generic option contract instrument.OptionSpread
: Represents a generic option spread instrument.Synthetic
: Represents a synthetic instrument with prices derived from component instruments using a formula.
Bars and aggregation
Introduction to Bars
A bar (also known as a candle, candlestick or kline) is a data structure that represents price and volume information over a specific period, including:
- Opening price
- Highest price
- Lowest price
- Closing price
- Traded volume (or ticks as a volume proxy)
These bars are generated using an aggregation method, which groups data based on specific criteria.
Purpose of data aggregation
Data aggregation in NautilusTrader transforms granular market data into structured bars or candles for several reasons:
- To provide data for technical indicators and strategy development.
- Because time-aggregated data (like minute bars) are often sufficient for many strategies.
- To reduce costs compared to high-frequency L1/L2/L3 market data.
Aggregation methods
The platform implements various aggregation methods:
Name | Description | Category |
---|---|---|
TICK | Aggregation of a number of ticks. | Threshold |
TICK_IMBALANCE | Aggregation of the buy/sell imbalance of ticks. | Threshold |
TICK_RUNS | Aggregation of sequential buy/sell runs of ticks. | Information |
VOLUME | Aggregation of traded volume. | Threshold |
VOLUME_IMBALANCE | Aggregation of the buy/sell imbalance of traded volume. | Threshold |
VOLUME_RUNS | Aggregation of sequential runs of buy/sell traded volume. | Information |
VALUE | Aggregation of the notional value of trades (also known as "Dollar bars"). | Threshold |
VALUE_IMBALANCE | Aggregation of the buy/sell imbalance of trading by notional value. | Information |
VALUE_RUNS | Aggregation of sequential buy/sell runs of trading by notional value. | Threshold |
MILLISECOND | Aggregation of time intervals with millisecond granularity. | Time |
SECOND | Aggregation of time intervals with second granularity. | Time |
MINUTE | Aggregation of time intervals with minute granularity. | Time |
HOUR | Aggregation of time intervals with hour granularity. | Time |
DAY | Aggregation of time intervals with day granularity. | Time |
WEEK | Aggregation of time intervals with week granularity. | Time |
MONTH | Aggregation of time intervals with month granularity. | Time |
Types of aggregation
NautilusTrader implements three distinct data aggregation methods:
-
Trade-to-bar aggregation: Creates bars from
TradeTick
objects (executed trades)- Use case: For strategies analyzing execution prices or when working directly with trade data.
- Always uses the
LAST
price type in the bar specification.
-
Quote-to-bar aggregation: Creates bars from
QuoteTick
objects (bid/ask prices)- Use case: For strategies focusing on bid/ask spreads or market depth analysis.
- Uses
BID
,ASK
, orMID
price types in the bar specification.
-
Bar-to-bar aggregation: Creates larger-timeframe
Bar
objects from smaller-timeframeBar
objects- Use case: For resampling existing smaller timeframe bars (1-minute) into larger timeframes (5-minute, hourly).
- Always requires the
@
symbol in the specification.
Bar types and Components
NautilusTrader defines a unique bar type (BarType
class) based on the following components:
- Instrument ID (
InstrumentId
): Specifies the particular instrument for the bar. - Bar Specification (
BarSpecification
):step
: Defines the interval or frequency of each bar.aggregation
: Specifies the method used for data aggregation (see the above table).price_type
: Indicates the price basis of the bar (e.g., bid, ask, mid, last).
- Aggregation Source (
AggregationSource
): Indicates whether the bar was aggregated internally (within Nautilus) - or externally (by a trading venue or data provider).
Bar types can also be classified as either standard or composite:
- Standard: Generated from granular market data, such as quote-ticks or trade-ticks.
- Composite: Derived from a higher-granularity bar type through subsampling (like 5-MINUTE bars aggregate from 1-MINUTE bars).
Aggregation sources
Bar data aggregation can be either internal or external:
INTERNAL
: The bar is aggregated inside the local Nautilus system boundary.EXTERNAL
: The bar is aggregated outside the local Nautilus system boundary (typically by a trading venue or data provider).
For bar-to-bar aggregation, the target bar type is always INTERNAL
(since you're doing the aggregation within NautilusTrader),
but the source bars can be either INTERNAL
or EXTERNAL
, i.e., you can aggregate externally provided bars or already
aggregated internal bars.
Defining Bar Types with String Syntax
Standard bars
You can define standard bar types from strings using the following convention:
{instrument_id}-{step}-{aggregation}-{price_type}-{INTERNAL | EXTERNAL}
For example, to define a BarType
for AAPL trades (last price) on Nasdaq (XNAS) using a 5-minute interval
aggregated from trades locally by Nautilus:
bar_type = BarType.from_str("AAPL.XNAS-5-MINUTE-LAST-INTERNAL")
Composite bars
Composite bars are derived by aggregating higher-granularity bars into the desired bar type. To define a composite bar, use this convention:
{instrument_id}-{step}-{aggregation}-{price_type}-INTERNAL@{step}-{aggregation}-{INTERNAL | EXTERNAL}
Notes:
- The derived bar type must use an
INTERNAL
aggregation source (since this is how the bar is aggregated). - The sampled bar type must have a higher granularity than the derived bar type.
- The sampled instrument ID is inferred to match that of the derived bar type.
- Composite bars can be aggregated from
INTERNAL
orEXTERNAL
aggregation sources.
For example, to define a BarType
for AAPL trades (last price) on Nasdaq (XNAS) using a 5-minute interval
aggregated locally by Nautilus, from 1-minute interval bars aggregated externally:
bar_type = BarType.from_str("AAPL.XNAS-5-MINUTE-LAST-INTERNAL@1-MINUTE-EXTERNAL")