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

OrderBookDepth

OrderBookDepth represents a snapshot with a variable number of bid and ask levels. Use it when a venue publishes a self-contained depth snapshot rather than incremental deltas.

Fields

FieldRust typePython typeRequired/defaultNotes
instrument_idInstrumentIdInstrumentIdRequiredInstrument whose book is represented.
bidsSmallVec<[BookOrder; 10]>list[BookOrder]RequiredBid levels in book order.
asksSmallVec<[BookOrder; 10]>list[BookOrder]RequiredAsk levels in book order.
bid_countsSmallVec<[u32; 10]>list[int]RequiredNumber of bid orders at each level.
ask_countsSmallVec<[u32; 10]>list[int]RequiredNumber of ask orders at each level.
flagsu8intRequiredRecordFlag bit field for event metadata.
sequenceu64intRequiredVenue sequence number, or zero if absent.
ts_eventUnixNanosintRequiredEvent timestamp in nanoseconds.
ts_initUnixNanosintRequiredInitialization timestamp in nanoseconds.

Behavior

  • Rust and PyO3 Python constructors accept variable-length sides. Each side requires one count per order; bid and ask sides can have different lengths.
  • Empty sides use empty sequences. The inline capacity is ten; larger snapshots allocate as needed.
  • This type is not interchangeable with incremental OrderBookDelta streams.

The former OrderBookDepth10 type name is gone. Catalog directories named order_book_depth10 still migrate, and Arrow files that stored that type in schema metadata still transcode. The legacy C FFI and the fixed-depth SBE encoding require exactly ten levels per side.

Example

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

let bids = vec![BookOrder::new(OrderSide::Buy, Price::from("2500.10"), Quantity::from("3.5"), 1)];
let asks = vec![BookOrder::new(OrderSide::Sell, Price::from("2500.20"), Quantity::from("2.0"), 2)];

let depth = OrderBookDepth::new(
    InstrumentId::from("ETHUSDT-PERP.BINANCE"),
    bids,
    asks,
    vec![1],
    vec![1],
    0,
    42,
    UnixNanos::from(1_000_000_000),
    UnixNanos::from(1_000_000_100),
);

On this page