nautechsystems/nautilus_trader · error

L2 delta should be processed

Error message

L2 delta should be processed

What it means

Benchmark panic from `.expect("L2 delta should be processed")` on `OrderMatchingEngine::process_order_book_delta`, which returns `Err` when an Add/Update delta's order price or size precision does not match the instrument's precision, or when `book.apply_delta` fails (e.g. an invalid or inconsistent L2 delta). Every generated market-data delta must apply cleanly to the L2_MBP book.

Source

Thrown at crates/execution/benches/matching_engine.rs:166

                        trades.last().unwrap().ts_event
                    );
                    assert_events(state, EventCounts::default());
                },
            )
        });
    });

    group.bench_function(BenchmarkId::new("delta_l2", MARKET_DATA_COUNT), |b| {
        b.iter_custom(|iters| {
            run_iterations(
                iters,
                || build_engine(BookType::L2_MBP),
                |state| {
                    for delta in &deltas {
                        state
                            .engine
                            .process_order_book_delta(black_box(delta))
                            .expect("L2 delta should be processed");
                    }
                },
                |state| {
                    assert_eq!(
                        state.engine.get_book().update_count,
                        MARKET_DATA_COUNT as u64,
                    );
                    assert_eq!(
                        state.engine.get_book().ts_last,
                        deltas.last().unwrap().ts_event
                    );
                    assert!(state.engine.get_book().has_ask());
                    assert_events(state, EventCounts::default());
                },
            )
        });
    });

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Regenerate/round benchmark deltas to exactly the instrument's `price_precision` and `size_precision` (use the instrument's price increment/step size).
  2. Verify the delta generator produces valid `BookAction::Add/Update/Delete/Clear` sequences (e.g. Add before Update/Delete).
  3. Check the `anyhow` error text — it names which precision check ("delta order price"/"delta order size") or apply_delta step failed.

Example fix

// before
state.engine.process_order_book_delta(black_box(delta)).expect("L2 delta should be processed");
// after
state.engine.process_order_book_delta(black_box(delta))
    .unwrap_or_else(|e| panic!("delta {:?} rejected: {e}", delta.action));
// and build prices via instrument precision:
let price = Price::new(raw, instrument.price_precision);
Defensive patterns

Strategy: validation

Validate before calling

fn delta_fits_instrument(delta: &OrderBookDelta, inst: &InstrumentAny) -> bool {
    delta.order.price.precision == inst.price_precision()
        && delta.order.size.precision == inst.size_precision()
}

Type guard

fn has_valid_precision(p: u8, expected: u8) -> bool { p == expected }

Try / catch

if let Err(e) = engine.process_order_book_delta(delta) {
    log::error!("delta rejected (check price/size precision vs instrument): {e}");
}

Prevention

When it happens

Trigger: A generated delta whose `order.price.precision` or `order.size.precision` differs from the instrument definition used in `build_engine`; a malformed delta (bad action/flags/order) rejected by `book.apply_delta`; applying a Delete/Clear delta with NULL_ORDER where an order is required.

Common situations: Instrument precision changed (tick/step size) while the synthetic delta generator still emits old precision; hand-built test deltas with raw f64-rounded prices; switching `BookType` so L1 ignores deltas but L2 validates them.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/8c80a10d6e44e648. Report an issue: GitHub.