{"record":{"id":"ef85f7d98aeadd7c","repo":"nautechsystems/nautilus_trader","slug":"invalid-field-name-value","errorCode":null,"errorMessage":"Invalid {field_name} value","messagePattern":"Invalid (.+?) value","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/common/parse.rs","lineNumber":191,"sourceCode":"    Ok((contract_decimal, size_increment))\n}\n\n/// Converts an optional contract-count field (e.g. `lotSize`, `maxOrderQty`) into a Nautilus\n/// quantity using the previously derived contract size.\n///\n/// # Errors\n///\n/// Returns an error when the raw value cannot be represented with the available precision.\npub fn convert_contract_quantity(\n    value: Option<f64>,\n    contract_decimal: Decimal,\n    max_scale: u32,\n    field_name: &str,\n) -> anyhow::Result<Option<Quantity>> {\n    value\n        .map(|raw| {\n            let mut decimal = Decimal::from_str(&raw.to_string())\n                .map_err(|_| anyhow::anyhow!(\"Invalid {field_name} value\"))?\n                * contract_decimal;\n            let scale = decimal.scale();\n            if scale > max_scale {\n                decimal = decimal\n                    .round_dp_with_strategy(max_scale, RoundingStrategy::MidpointAwayFromZero);\n            }\n            let decimal = decimal.normalize();\n            let precision = decimal.scale() as u8;\n            Quantity::from_decimal_dp(decimal, precision).map_err(anyhow::Error::from)\n        })\n        .transpose()\n}\n\n/// Converts a signed BitMEX contracts value into a Nautilus quantity using instrument precision.\n#[must_use]\npub fn parse_signed_contracts_quantity(value: i64, instrument: &InstrumentAny) -> Quantity {\n    let abs_value = value.checked_abs().unwrap_or_else(|| {\n        log::warn!(\"Quantity value {value} overflowed when taking absolute value\");","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/common/parse.rs#L173-L209","documentation":"convert_contract_quantity converts an optional raw numeric field (e.g. contract-specific min/max quantity) into a Quantity by multiplying with the contract decimal. It fails when the raw value string cannot be parsed into a Decimal, i.e. the exchange sent a non-finite or otherwise unparsable number for the named field.","triggerScenarios":"Parsing a spot/perpetual/futures instrument whose minQty/maxQty/lotSize-style field (identified by field_name) is NaN, infinite, or not Decimal-representable.","commonSituations":"Unexpected instrument metadata from BitMEX (null coerced oddly, float inf), or test fixtures with placeholder values.","solutions":["Look at field_name in the message to identify which quantity field is malformed and inspect the raw instrument payload","Fix or filter the instrument definition before re-running the adapter","Validate the raw f64 is finite before calling convert_contract_quantity"],"exampleFix":"// before\nconvert_contract_quantity(Some(raw_min_qty), ...)\n// after\nif raw_min_qty.is_finite() {\n    convert_contract_quantity(Some(raw_min_qty), ...)\n} else {\n    anyhow::bail!(\"non-finite {} for {}\", field_name, symbol);\n}","handlingStrategy":"validation","validationCode":"fn valid_quantity_field(raw: f64) -> bool { raw.is_finite() && raw > 0.0 }","typeGuard":"fn finite_f64(x: f64) -> bool { x.is_finite() }","tryCatchPattern":"match convert_contract_quantity(value, cd, max_scale, field_name) {\n    Ok(q) => q,\n    Err(e) if e.to_string().contains(field_name) => {\n        log::warn!(\"bad {} from exchange, skipping instrument\", field_name);\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Validate raw f64 fields are finite before instrument conversion","Log field_name alongside the error to locate the offending instrument attribute","Filter instrument lists to well-formed rows before adapter ingestion"],"tags":["instrument-parsing","decimal","quantity"],"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"}