{"record":{"id":"10bd8ec0398dfe82","repo":"nautechsystems/nautilus_trader","slug":"invalid-bid-price-for-orderbook-filtered-view","errorCode":null,"errorMessage":"Invalid bid price for OrderBook::filtered_view","messagePattern":"Invalid bid price for OrderBook::filtered_view","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/orderbook/book.rs","lineNumber":823,"sourceCode":"        let asks_map = self.asks_filtered_as_map(depth, own_book, status, accepted_buffer_ns, now);\n\n        let mut filtered_book = Self::new(self.instrument_id, self.book_type);\n        filtered_book.sequence = self.sequence;\n        filtered_book.ts_last = self.ts_last;\n\n        let sequence = self.sequence;\n        let ts_event = self.ts_last;\n\n        let mut order_id = 1_u64;\n\n        for (price, quantity) in bids_map {\n            if quantity <= Decimal::ZERO {\n                continue;\n            }\n\n            let order = BookOrder::new(\n                OrderSide::Buy,\n                Price::from_decimal(price).expect(\"Invalid bid price for OrderBook::filtered_view\"),\n                Quantity::from_decimal(quantity)\n                    .expect(\"Invalid bid quantity for OrderBook::filtered_view\"),\n                order_id,\n            );\n            order_id += 1;\n            filtered_book.add(order, 0, sequence, ts_event);\n        }\n\n        for (price, quantity) in asks_map {\n            if quantity <= Decimal::ZERO {\n                continue;\n            }\n\n            let order = BookOrder::new(\n                OrderSide::Sell,\n                Price::from_decimal(price).expect(\"Invalid ask price for OrderBook::filtered_view\"),\n                Quantity::from_decimal(quantity)\n                    .expect(\"Invalid ask quantity for OrderBook::filtered_view\"),","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/orderbook/book.rs#L805-L841","documentation":"OrderBook::filtered_view builds synthetic Buy orders from the (price, quantity) map passed in and converts each bid price with Price::from_decimal(...).expect(...). Price::from_decimal fails (returns None) when the decimal is NaN, infinite, or outside Price's representable precision/range, so a bid entry with a non-finite or out-of-range price panics with this message.","triggerScenarios":"Calling filtered_view (or py_filtered_view / filtered_view_checked) with a bids map containing a price that is NaN, infinite, negative-beyond-range, or with more precision than the instrument's Price precision allows.","commonSituations":"Computing filtered views from indicator/divergence math that produced NaN (e.g. division by zero); passing f64-derived decimals without normalization; using precision inconsistent with the instrument definition.","solutions":["Validate each bid price is finite and within the instrument's price range/precision before calling filtered_view.","Round/truncate prices to the instrument precision with the project's price rounding utilities before building the map.","Skip non-finite entries in your map-building code instead of inserting them.","If the values come from external JSON/config, sanitize them (reject NaN/Inf) at parse time.","Consider contributing/using a checked variant that returns Result instead of panicking if you cannot pre-validate."],"exampleFix":"// before\nlet bids: BTreeMap<Price, Quantity> = raw_bid_map(); // may contain NaN\nlet view = book.filtered_view(&bids, &asks, None);\n// after\nlet bids: BTreeMap<Price, Quantity> = raw_bid_map()\n    .into_iter()\n    .filter(|(p, _)| p.as_decimal().is_finite() && p.as_decimal().is_positive())\n    .collect();\nlet view = book.filtered_view(&bids, &asks, None);","handlingStrategy":"validation","validationCode":"fn valid_bid(p: &Price) -> bool {\n    let d = p.as_decimal();\n    d.is_finite() && d.is_sign_positive()\n}\nlet bids: Vec<_> = map.iter().filter(|(p, _)| valid_bid(p)).collect();","typeGuard":"fn is_valid_price(p: &Price) -> bool {\n    p.as_decimal().is_finite()\n}","tryCatchPattern":"// Panic-based; guard inputs before calling filtered_view. In Python research code:\ntry:\n    view = book.filtered_view(bids, asks, None)\nexcept BaseException as e:\n    log.warning(\"filtered_view failed: %s\", e)","preventionTips":["Round prices to instrument precision before building maps.","Filter NaN/Inf at the point the map is constructed.","Sanitize external data sources at parse time."],"tags":["rust","orderbook","panic","invalid-argument-value","decimal"],"backgroundTag":"invalid-argument-value","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"}