nautechsystems/nautilus_trader · error

invalid non-positive {name} price

Error message

invalid non-positive {name} price

What it means

Thrown when a parsed bid or ask level price is zero or negative. A valid order-book level must have a strictly positive price; `anyhow::ensure!(price.is_positive(), ...)` rejects anything else before the level is added to the book.

Source

Thrown at crates/adapters/binance/src/spot/http/client.rs:3077

        instrument: &InstrumentAny,
        snapshot: &BinanceDepth,
        ts_event: UnixNanos,
    ) -> anyhow::Result<OrderBook> {
        let sequence = u64::try_from(snapshot.last_update_id)
            .map_err(|_| anyhow::anyhow!("invalid negative order-book update ID"))?;
        let mut book = OrderBook::new(instrument_id, BookType::L2_MBP);
        let mut add_level = |level: &super::models::BinancePriceLevel,
                             side: OrderSide,
                             order_id: usize,
                             name: &str|
         -> anyhow::Result<()> {
            let price = Price::from_mantissa_exponent_checked(
                level.price_mantissa,
                snapshot.price_exponent,
                instrument.price_precision(),
            )
            .map_err(|e| anyhow::anyhow!("invalid {name} price: {e}"))?;
            anyhow::ensure!(price.is_positive(), "invalid non-positive {name} price");
            let qty_mantissa = u64::try_from(level.qty_mantissa)
                .map_err(|_| anyhow::anyhow!("invalid negative {name} quantity"))?;
            let quantity = Quantity::from_mantissa_exponent_checked(
                qty_mantissa,
                snapshot.qty_exponent,
                instrument.size_precision(),
            )
            .map_err(|e| anyhow::anyhow!("invalid {name} quantity: {e}"))?;
            anyhow::ensure!(
                quantity.is_positive(),
                "invalid non-positive {name} quantity"
            );
            let order = BookOrder::new(
                side,
                price,
                quantity,
                u64::try_from(order_id)
                    .map_err(|_| anyhow::anyhow!("order-book level index overflow"))?,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Re-fetch the snapshot; a single bad response is typically transient.
  2. Inspect the raw JSON levels to find the offending zero/negative price.
  3. Fix any proxy/mock fixtures to return realistic positive prices.
  4. Report to the adapter maintainers if a genuine Binance response violates this.
Defensive patterns

Strategy: validation

Validate before calling

fn prices_positive(snapshot: &BinanceDepth) -> bool {
    snapshot.bids.iter().chain(snapshot.asks.iter()).all(|l| l.price_mantissa > 0)
}

Type guard

fn positive_level(l: &BinancePriceLevel) -> bool { l.price_mantissa > 0 }

Try / catch

match client.request_book_snapshot(id, depth).await {
    Ok(book) => book,
    Err(e) if e.to_string().contains("non-positive") => fetch_fresh_snapshot(id, depth).await?,
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `request_book_snapshot` when any depth level decodes to a non-positive price — a malformed or synthetic depth response containing 0 or negative price mantissas.

Common situations: Mock servers or fixtures emitting zero-priced levels; corrupted responses from proxies; upstream API anomalies or schema changes.

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/0a0804451b274ff9. Report an issue: GitHub.