{"record":{"id":"4cf66140458c3acb","repo":"nautechsystems/nautilus_trader","slug":"invalid-negative-name-quantity","errorCode":null,"errorMessage":"invalid negative {name} quantity","messagePattern":"invalid negative (.+?) quantity","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/http/client.rs","lineNumber":3079,"sourceCode":"        ts_event: UnixNanos,\n    ) -> anyhow::Result<OrderBook> {\n        let sequence = u64::try_from(snapshot.last_update_id)\n            .map_err(|_| anyhow::anyhow!(\"invalid negative order-book update ID\"))?;\n        let mut book = OrderBook::new(instrument_id, BookType::L2_MBP);\n        let mut add_level = |level: &super::models::BinancePriceLevel,\n                             side: OrderSide,\n                             order_id: usize,\n                             name: &str|\n         -> anyhow::Result<()> {\n            let price = Price::from_mantissa_exponent_checked(\n                level.price_mantissa,\n                snapshot.price_exponent,\n                instrument.price_precision(),\n            )\n            .map_err(|e| anyhow::anyhow!(\"invalid {name} price: {e}\"))?;\n            anyhow::ensure!(price.is_positive(), \"invalid non-positive {name} price\");\n            let qty_mantissa = u64::try_from(level.qty_mantissa)\n                .map_err(|_| anyhow::anyhow!(\"invalid negative {name} quantity\"))?;\n            let quantity = Quantity::from_mantissa_exponent_checked(\n                qty_mantissa,\n                snapshot.qty_exponent,\n                instrument.size_precision(),\n            )\n            .map_err(|e| anyhow::anyhow!(\"invalid {name} quantity: {e}\"))?;\n            anyhow::ensure!(\n                quantity.is_positive(),\n                \"invalid non-positive {name} quantity\"\n            );\n            let order = BookOrder::new(\n                side,\n                price,\n                quantity,\n                u64::try_from(order_id)\n                    .map_err(|_| anyhow::anyhow!(\"order-book level index overflow\"))?,\n            );\n            book.add(order, 0, sequence, ts_event);","sourceCodeStart":3061,"sourceCodeEnd":3097,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/http/client.rs#L3061-L3097","documentation":"Thrown when a bid or ask level's `qty_mantissa` is negative and cannot be converted to the unsigned `u64` quantity mantissa. Quantities are inherently non-negative, so a negative mantissa indicates a malformed level payload.","triggerScenarios":"Calling `request_book_snapshot` when any depth level carries a negative quantity mantissa in the `/api/v3/depth` response.","commonSituations":"Corrupted or synthetic responses from proxies/mocks; upstream encoding anomalies; hand-written test fixtures with negative quantities.","solutions":["Re-fetch the depth snapshot to rule out a transient bad payload.","Inspect the raw JSON to locate the level with the negative quantity.","Fix mock/fixture data to use non-negative quantity mantissas.","Report a bug if a genuine Binance response contains negative quantities."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn quantities_non_negative(snapshot: &BinanceDepth) -> bool {\n    snapshot.bids.iter().chain(snapshot.asks.iter()).all(|l| l.qty_mantissa >= 0)\n}","typeGuard":"fn non_neg_qty(l: &BinancePriceLevel) -> bool { l.qty_mantissa >= 0 }","tryCatchPattern":"match client.request_book_snapshot(id, depth).await {\n    Ok(book) => book,\n    Err(e) if e.to_string().contains(\"negative\") && e.to_string().contains(\"quantity\") => retry_snapshot(id, depth).await?,\n    Err(e) => return Err(e),\n}","preventionTips":["Re-fetch snapshots when a payload fails unsigned-conversion checks.","Ensure mock fixtures use non-negative quantity mantissas.","Bypass payload-rewriting intermediaries."],"tags":["orderbook","binance","quantity","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}