nautechsystems/nautilus_trader · error

Failed to decode MboMsg

Error message

Failed to decode MboMsg

What it means

Inside `read_order_book_deltas`, after advancing, the record must decode as a `dbn::MboMsg`. `RecordRef::get::<MboMsg>()` returns None when the record's rtype does not correspond to MBO data, so the loader raises this error rather than silently skipping.

Source

Thrown at crates/adapters/databento/src/loader.rs:491

                    dbn_stream
                        .advance()
                        .map_err(|e| anyhow::anyhow!("Stream advance error: {e}"))?;

                    let Some(rec) = dbn_stream.get() else {
                        return Ok(false);
                    };
                    let record = dbn::RecordRef::from(rec);
                    let instrument_id = self
                        .resolve_record_instrument_id(&record, instrument_id, &mut metadata_cache)
                        .context("failed to decode instrument id")?;
                    let resolved_precision = self.resolve_stream_price_precision(
                        &instrument_id,
                        fixed_instrument_id,
                        &mut fixed_price_precision,
                    )?;
                    let msg = record
                        .get::<dbn::MboMsg>()
                        .ok_or_else(|| anyhow::anyhow!("Failed to decode MboMsg"))?;
                    let (delta, _trade) =
                        decode_mbo_msg(msg, instrument_id, resolved_precision, None, false)?;
                    delta_buffer.push(msg, instrument_id, delta);
                    Ok(true)
                })();

                match result {
                    Ok(true) => {}
                    Ok(false) => {
                        delta_buffer.finish();
                        finished = true;
                    }
                    Err(e) => {
                        delta_buffer.finish();
                        terminal_error = Some(e);
                        finished = true;
                    }
                }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Request `schema = "mbo"` (rtype MBO) when downloading the data from Databento
  2. Use `load_trade_ticks`/`load_quote_ticks` for non-MBO schemas instead
  3. Filter the stream to records with the MBO rtype before loading
  4. Verify the file's first record header rtype with a DBN inspection tool

Example fix

// before
let data = databento historical.get(
    dataset="GLBX.L3", symbols=[...], schema="tbbo", ...
);
let deltas = loader.load_order_book_deltas(file)?; // panics with Failed to decode MboMsg
// after
let data = databento historical.get(
    dataset="GLBX.L3", symbols=[...], schema="mbo", ...
);
let deltas = loader.load_order_book_deltas(file)?;
Defensive patterns

Strategy: validation

Validate before calling

// ensure the request used the MBO schema before loading deltas
assert_eq!(request.schema, "mbo", "order book deltas require schema=mbo");

Type guard

fn is_mbo_record(rec: &dbn::RecordRef) -> bool {
    rec.get::<dbn::MboMsg>().is_some()
}

Try / catch

match loader.load_order_book_deltas(file, instrument_id, price_precision) {
    Ok(d) => d,
    Err(e) if e.to_string().contains("Failed to decode MboMsg") => {
        anyhow::bail!("input is not MBO data; re-download with schema=mbo");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Feeding a DBN stream containing non-MBO records (trades, quotes, OHLCV) into `read_order_book_deltas`/`load_order_book_deltas`, which expects rtype MBO records exclusively.

Common situations: Requesting the wrong schema/rtype from Databento (e.g. `trades` or `tbbo` instead of `mbo`) and piping the file into the order book delta loader; mixing multiple schemas in one file.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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