{"record":{"id":"1be603324f266978","repo":"nautechsystems/nautilus_trader","slug":"invalid-ask-price-for-orderbook-filtered-view","errorCode":null,"errorMessage":"Invalid ask price for OrderBook::filtered_view","messagePattern":"Invalid ask price for OrderBook::filtered_view","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/orderbook/book.rs","lineNumber":839,"sourceCode":"            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\"),\n                order_id,\n            );\n            order_id += 1;\n            filtered_book.add(order, 0, sequence, ts_event);\n        }\n\n        Ok(filtered_book)\n    }\n\n    /// Groups bid quantities into price buckets, truncating to a maximum depth, excluding own orders.\n    ///\n    /// With `own_book`, subtracts own order sizes, filtered by `status` if provided.\n    /// When `now` is provided, only subtracts orders whose acceptance time plus\n    /// `accepted_buffer_ns` is at or before `now`. When `now` is `None`, acceptance-time\n    /// filtering is disabled.\n    ///","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/orderbook/book.rs#L821-L857","documentation":"OrderBook::filtered_view builds synthetic Sell orders from the asks map and converts each ask price with Price::from_decimal(...).expect(...), panicking with this message when conversion fails. from_decimal fails for NaN, infinite, or precision/range-incompatible decimals, so an ask entry with such a price aborts the call.","triggerScenarios":"Calling filtered_view / py_filtered_view with an asks map containing a NaN, infinite, or out-of-range price (e.g. sentinel values like u64::MAX converted to decimal, or f64 infinity from upstream math).","commonSituations":"Ask maps built from vendor feeds using invalid/no-price sentinels; NaN propagation from indicator calculations; precision mismatch with the instrument's price precision.","solutions":["Pre-validate ask prices: finite, positive, and rounded to instrument price precision.","Drop or clamp sentinel/invalid price entries when building the asks map.","Normalize floats via Decimal carefully (from_f64_retain) and verify finiteness before conversion.","Sanitize external data sources at parse time so invalid prices never reach filtered_view.","Wrap your own map construction in a validator function shared by bid/ask paths to keep both sides consistent."],"exampleFix":"// before\nasks.insert(Price::from_raw(sentinel_raw), qty); // sentinel leaks into filtered_view\n// after\nlet dec = price.as_decimal();\nif dec.is_finite() && dec.is_sign_positive() {\n    asks.insert(price, qty);\n}","handlingStrategy":"validation","validationCode":"fn valid_ask(p: &Price) -> bool {\n    let d = p.as_decimal();\n    d.is_finite() && d.is_sign_positive()\n}\nlet asks: Vec<_> = map.iter().filter(|(p, _)| valid_ask(p)).collect();","typeGuard":"fn is_valid_price(p: &Price) -> bool {\n    p.as_decimal().is_finite()\n}","tryCatchPattern":"// Pre-validate ask prices; the library panics rather than returning Result. Python:\ntry:\n    view = book.filtered_view(bids, asks, None)\nexcept BaseException as e:\n    log.warning(\"filtered_view failed: %s\", e)","preventionTips":["Reject sentinel prices when ingesting vendor data.","Centralize price sanitization for bid and ask paths.","Assert price precision matches the instrument."],"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"}