{"record":{"id":"547e0c21297ce3bb","repo":"nautechsystems/nautilus_trader","slug":"invalid-negative-order-book-update-id","errorCode":null,"errorMessage":"invalid negative order-book update ID","messagePattern":"invalid negative order-book update ID","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/http/client.rs","lineNumber":3134,"sourceCode":"        instrument_id: InstrumentId,\n        depth: Option<u32>,\n    ) -> anyhow::Result<OrderBook> {\n        if depth.is_some_and(|value| !crate::common::consts::BINANCE_BOOK_DEPTHS.contains(&value)) {\n            anyhow::bail!(\n                \"invalid Binance Futures order-book depth; valid values are {:?}\",\n                crate::common::consts::BINANCE_BOOK_DEPTHS\n            );\n        }\n        let (symbol, price_precision, size_precision) =\n            self.cached_precisions_by_id(instrument_id)?;\n        let params = BinanceDepthParams {\n            symbol,\n            limit: depth,\n        };\n        let snapshot = self.inner.depth(&params).await?;\n        let ts_event = self.clock.get_time_ns();\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        for (index, level) in snapshot.bids.iter().enumerate() {\n            let order = BookOrder::new(\n                OrderSide::Buy,\n                parse_required_price_at_precision(&level.0, price_precision, \"bid price\")?,\n                parse_required_quantity_at_precision(&level.1, size_precision, \"bid quantity\")?,\n                index as u64,\n            );\n            book.add(order, 0, sequence, ts_event);\n        }\n        let bid_count = snapshot.bids.len();\n        for (index, level) in snapshot.asks.iter().enumerate() {\n            let order = BookOrder::new(\n                OrderSide::Sell,\n                parse_required_price_at_precision(&level.0, price_precision, \"ask price\")?,\n                parse_required_quantity_at_precision(&level.1, size_precision, \"ask quantity\")?,\n                (bid_count + index) as u64,\n            );","sourceCodeStart":3116,"sourceCodeEnd":3152,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/http/client.rs#L3116-L3152","documentation":"Thrown when converting the Binance USD-M Futures depth snapshot's last_update_id (an i64 field) to u64 fails, which only happens if the exchange returned a negative update ID. The library requires order-book sequence numbers to be non-negative so they can be stored as u64 and compared/ordered. It signals that the snapshot response is malformed or from an unexpected API response.","triggerScenarios":"Calling the futures depth (order book snapshot) HTTP request via BinanceFuturesHttpClient when the deserialized snapshot.last_update_id is negative, e.g. a corrupt or nonstandard response body deserialized into a signed field.","commonSituations":"Mock/stubbed servers or proxies returning synthetic negative IDs; a Binance API behavior change or an unexpected error payload being misdeserialized into the depth response struct.","solutions":["Re-fetch the depth snapshot; a one-off malformed response resolves on retry","Log snapshot.last_update_id raw value to confirm the API/proxy returned a negative ID","Check for API version mismatches between the adapter and the deployed Binance futures REST endpoint","If using a mock/proxy, fix it to emit non-negative update IDs"],"exampleFix":"// before: let sequence = u64::try_from(snapshot.last_update_id)\n//     .map_err(|_| anyhow::anyhow!(\"invalid negative order-book update ID\"))?;\n// after: guard and retry\nlet sequence = u64::try_from(snapshot.last_update_id)\n    .map_err(|_| anyhow::anyhow!(\"invalid negative order-book update ID: {}\", snapshot.last_update_id))?;","handlingStrategy":"validation","validationCode":"if snapshot.last_update_id < 0 {\n    return Err(anyhow::anyhow!(\"negative update id {}\", snapshot.last_update_id));\n}\nlet sequence = snapshot.last_update_id as u64;","typeGuard":"fn is_valid_update_id(id: i64) -> bool { id >= 0 }","tryCatchPattern":"match u64::try_from(snapshot.last_update_id) {\n    Ok(seq) => seq,\n    Err(_) => { warn!(\"bad snapshot update id, refetching\"); return refetch_snapshot().await; }\n}","preventionTips":["Retry the snapshot request on malformed responses","Validate deserialized payloads before building the order book","Pin adapter version to the matching Binance futures API behavior","Avoid proxies/mocks that emit synthetic negative IDs"],"tags":["rust","order-book","binance-futures","data-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-23T08:17:48.524Z"}