nautechsystems/nautilus_trader · error
Invalid bid price for OrderBook::filtered_view
Error message
Invalid bid price for OrderBook::filtered_view
What it means
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.
Source
Thrown at crates/model/src/orderbook/book.rs:823
let asks_map = self.asks_filtered_as_map(depth, own_book, status, accepted_buffer_ns, now);
let mut filtered_book = Self::new(self.instrument_id, self.book_type);
filtered_book.sequence = self.sequence;
filtered_book.ts_last = self.ts_last;
let sequence = self.sequence;
let ts_event = self.ts_last;
let mut order_id = 1_u64;
for (price, quantity) in bids_map {
if quantity <= Decimal::ZERO {
continue;
}
let order = BookOrder::new(
OrderSide::Buy,
Price::from_decimal(price).expect("Invalid bid price for OrderBook::filtered_view"),
Quantity::from_decimal(quantity)
.expect("Invalid bid quantity for OrderBook::filtered_view"),
order_id,
);
order_id += 1;
filtered_book.add(order, 0, sequence, ts_event);
}
for (price, quantity) in asks_map {
if quantity <= Decimal::ZERO {
continue;
}
let order = BookOrder::new(
OrderSide::Sell,
Price::from_decimal(price).expect("Invalid ask price for OrderBook::filtered_view"),
Quantity::from_decimal(quantity)
.expect("Invalid ask quantity for OrderBook::filtered_view"),View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let bids: BTreeMap<Price, Quantity> = raw_bid_map(); // may contain NaN
let view = book.filtered_view(&bids, &asks, None);
// after
let bids: BTreeMap<Price, Quantity> = raw_bid_map()
.into_iter()
.filter(|(p, _)| p.as_decimal().is_finite() && p.as_decimal().is_positive())
.collect();
let view = book.filtered_view(&bids, &asks, None); Defensive patterns
Strategy: validation
Validate before calling
fn valid_bid(p: &Price) -> bool {
let d = p.as_decimal();
d.is_finite() && d.is_sign_positive()
}
let bids: Vec<_> = map.iter().filter(|(p, _)| valid_bid(p)).collect(); Type guard
fn is_valid_price(p: &Price) -> bool {
p.as_decimal().is_finite()
} Try / catch
// Panic-based; guard inputs before calling filtered_view. In Python research code:
try:
view = book.filtered_view(bids, asks, None)
except BaseException as e:
log.warning("filtered_view failed: %s", e) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- Invalid bid quantity for OrderBook::filtered_view
- Invalid ask price for OrderBook::filtered_view
- Invalid ask quantity for OrderBook::filtered_view
- Decimal average price must parse as f64
- Invalid parity transformed price for OwnOrderBook::combined_
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/10bd8ec0398dfe82.
Report an issue: GitHub.