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

OrderBookDeltas

OrderBookDeltas groups a non-empty batch of OrderBookDelta records that belong to the same logical book event. It reduces per-message overhead when adapters receive or produce multiple book changes at once.

Fields

FieldRust typePython typeRequired/defaultNotes
instrument_idInstrumentIdInstrumentIdRequiredInstrument whose book is changing.
deltasVec<OrderBookDelta>list[OrderBookDelta]RequiredNon‑empty batch of deltas.
flagsu8intFrom last deltaLast delta flags.
sequenceu64intFrom last deltaLast delta sequence number.
ts_eventUnixNanosintFrom last deltaLast delta event timestamp.
ts_initUnixNanosintFrom last deltaLast delta initialization timestamp.

Behavior

  • The batch must contain at least one delta.
  • The batch metadata mirrors the final delta.
  • The final delta should carry F_LAST when it closes a logical event group.
  • Snapshot batches usually begin with a CLEAR delta and end with F_SNAPSHOT | F_LAST.

Example

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

let instrument_id = InstrumentId::from("ETHUSDT-PERP.BINANCE");
let bid = OrderBookDelta::new(
    instrument_id,
    BookAction::Add,
    BookOrder::new(OrderSide::Buy, Price::from("2500.10"), Quantity::from("3.5"), 1),
    0,
    41,
    UnixNanos::from(1_000_000_000),
    UnixNanos::from(1_000_000_100),
);
let ask = OrderBookDelta::new(
    instrument_id,
    BookAction::Add,
    BookOrder::new(OrderSide::Sell, Price::from("2500.20"), Quantity::from("2.0"), 2),
    RecordFlag::F_LAST as u8,
    42,
    UnixNanos::from(1_000_000_000),
    UnixNanos::from(1_000_000_100),
);

let deltas = OrderBookDeltas::new(instrument_id, vec![bid, ask]);

On this page