NautilusTrader
ConceptsData
These docs track the unreleased nightly build and may change without notice. Switch to the latest stable docs.

OrderBookDelta

OrderBookDelta represents one change to an order book. It is the most granular built-in book data type and supports the book types NautilusTrader uses for incremental updates:

  • L3_MBO: Level 3 market-by-order (MBO) data.
  • L2_MBP: Level 2 market-by-price (MBP) data.
  • L1_MBP: Level 1 market-by-price (MBP) top-of-book data.

The source feed and target BookType determine which granularity a delta carries.

Use it when a venue or data provider publishes incremental book changes and Nautilus should maintain the book state locally.

Fields

FieldRust typePython typeRequired/defaultNotes
instrument_idInstrumentIdInstrumentIdRequiredInstrument whose book is changing.
actionBookActionBookActionRequiredADD, UPDATE, DELETE, or CLEAR.
orderBookOrderBookOrderRequiredPrice, size, side, and order ID payload.
flagsu8intRequiredRecordFlag bit field for event metadata.
sequenceu64intRequiredVenue sequence number, or zero if absent.
ts_eventUnixNanosintRequiredEvent timestamp in nanoseconds.
ts_initUnixNanosintRequiredInitialization timestamp in nanoseconds.

BookOrder fields

The order field contains the BookOrder payload for the delta.

FieldRust typePython typeNotes
sideOption<OrderSide>OrderSide | NoneOrder side.
pricePricePriceOrder price.
sizeQuantityQuantityOrder size.
order_idOrderId (u64)intOrder ID carried by the source feed.

The null/default order uses None for its side, with zero price, zero size, and zero order ID.

BookAction variants

Rust variantPython variantValueMeaning
BookAction::AddADD1Adds an order to the book.
BookAction::UpdateUPDATE2Updates an existing order in the book.
BookAction::DeleteDELETE3Deletes an existing order in the book.
BookAction::ClearCLEAR4Clears the order book state.

Behavior

  • ADD and UPDATE deltas require a positive order size.
  • CLEAR deltas reset book state and use a null book order.
  • flags carries event boundary and snapshot metadata. See Delta flags and event boundaries.
  • Use OrderBookDelta::clear(...) in Rust or OrderBookDelta.clear(...) in Python to construct clear deltas.

Example

use nautilus_core::UnixNanos;
use nautilus_model::{
    data::{BookOrder, OrderBookDelta},
    enums::{BookAction, OrderSide, RecordFlag},
    identifiers::InstrumentId,
    types::{Price, Quantity},
};

let delta = OrderBookDelta::new(
    InstrumentId::from("ETHUSDT-PERP.BINANCE"),
    BookAction::Add,
    BookOrder::new(
        OrderSide::Buy,
        Price::from("2500.10"),
        Quantity::from("3.5"),
        12_345,
    ),
    RecordFlag::F_LAST as u8,
    42,
    UnixNanos::from(1_000_000_000),
    UnixNanos::from(1_000_000_100),
);

On this page