{"record":{"id":"7cc32220a179d774","repo":"nautechsystems/nautilus_trader","slug":"invalid-quantity-size-size-e","errorCode":null,"errorMessage":"invalid quantity size={size}: {e}","messagePattern":"invalid quantity size=(.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/data/parse.rs","lineNumber":32,"sourceCode":"// -------------------------------------------------------------------------------------------------\n\n//! Parsing utilities for converting Interactive Brokers data to Nautilus types.\n\nuse ibapi::contracts::{OptionComputation, tick_types::TickType};\nuse nautilus_core::UnixNanos;\nuse nautilus_model::{\n    data::{\n        Bar, BarType, IndexPriceUpdate, QuoteTick, TradeTick, greeks::OptionGreekValues,\n        option_chain::OptionGreeks,\n    },\n    enums::{AggressorSide, BookAction, GreeksConvention},\n    identifiers::{InstrumentId, TradeId},\n    types::{Price, Quantity},\n};\n\nfn checked_quantity(size: f64, precision: u8) -> anyhow::Result<Quantity> {\n    let quantity = Quantity::new_checked(size, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid quantity size={size}: {e}\"))?;\n    let tolerance = 10_f64.powi(-i32::from(precision)) * 1e-9;\n    if (quantity.as_f64() - size).abs() > tolerance {\n        anyhow::bail!(\n            \"quantity size={} cannot be represented with precision={}\",\n            size,\n            precision\n        );\n    }\n    Ok(quantity)\n}\n\n/// Parse IB tick price and size data into a QuoteTick.\n///\n/// This builds a quote from individual tick updates. You typically need to accumulate\n/// bid/ask prices and sizes from multiple tick updates before creating a QuoteTick.\n///\n/// # Errors\n///","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/data/parse.rs#L14-L50","documentation":"`checked_quantity` converts a raw `f64` size into a domain `Quantity` with the given precision. The error is thrown when `Quantity::new_checked` rejects the value (e.g. negative, NaN, or exceeding valid range) — the raw size and underlying error are included in the message.","triggerScenarios":"`parse_quote_tick` or `parse_trade_tick` receiving a size field from IB that is NaN, negative, zero-negatives (-0.0 edge), or otherwise rejected by `Quantity::new_checked` for the configured precision.","commonSituations":"IB streaming a bid/ask size of 0 sentinel values or NaN during auction/pre-open states; instrument configured with a precision that cannot represent the reported size; malformed historical data rows.","solutions":["Inspect the raw IB message and log `size` when this fires; identify whether the exchange sent NaN or an invalid sentinel.","Skip/ignore ticks with non-positive or NaN sizes before parsing instead of propagating the error.","Verify the instrument definition's size precision matches the IB contract's min tick/size; adjust instrument configuration if too restrictive.","Handle IB pre-open/auction states in client code where sizes may be placeholders."],"exampleFix":"// before\nlet quantity = checked_quantity(size, precision)?;\n// after\nif !size.is_finite() || size <= 0.0 {\n    return Ok(None); // skip invalid sizes from IB\n}\nlet quantity = checked_quantity(size, precision)?;","handlingStrategy":"validation","validationCode":"fn valid_size(size: f64) -> bool {\n    size.is_finite() && size > 0.0\n}\n","typeGuard":"fn is_representable(size: f64, precision: u8) -> bool {\n    size.is_finite() && size >= 0.0 && (size * 10f64.powi(i32::from(precision))).fract() == 0.0\n}\n","tryCatchPattern":"match checked_quantity(size, precision) {\n    Ok(q) => q,\n    Err(e) if e.to_string().starts_with(\"invalid quantity\") => {\n        log::debug!(\"dropping tick with invalid size {size}\");\n        return Ok(None);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Filter NaN/negative/zero sizes from IB messages before tick parsing.","Match instrument size precision to the contract's actual min tick.","Log dropped sizes with instrument id to spot systematic precision mismatches."],"tags":["interactive-brokers","data-parsing","quantity","validation"],"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-14T00:17:10.932Z"}