{"record":{"id":"7977f38a9265ef4a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-max-mkt-sz-for-e","errorCode":null,"errorMessage":"Failed to parse `max_mkt_sz` '{}' for {}: {e}","messagePattern":"Failed to parse `max_mkt_sz` '(.+?)' for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":1974,"sourceCode":"    })?;\n\n    if definition.lot_sz.is_empty() {\n        anyhow::bail!(\"`lot_sz` is empty for {}\", definition.inst_id);\n    }\n\n    let size_increment = Quantity::from_str(&definition.lot_sz).map_err(|e| {\n        anyhow::anyhow!(\n            \"Failed to parse `lot_sz` '{}' for {}: {e}\",\n            definition.lot_sz,\n            definition.inst_id,\n        )\n    })?;\n    let lot_size = Some(size_increment);\n    let max_quantity = if definition.max_mkt_sz.is_empty() {\n        None\n    } else {\n        Some(Quantity::from_str(&definition.max_mkt_sz).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to parse `max_mkt_sz` '{}' for {}: {e}\",\n                definition.max_mkt_sz,\n                definition.inst_id,\n            )\n        })?)\n    };\n    let min_quantity = if definition.min_sz.is_empty() {\n        None\n    } else {\n        Some(Quantity::from_str(&definition.min_sz).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to parse `min_sz` '{}' for {}: {e}\",\n                definition.min_sz,\n                definition.inst_id,\n            )\n        })?)\n    };\n    let max_notional: Option<Money> = None;","sourceCodeStart":1956,"sourceCodeEnd":1992,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L1956-L1992","documentation":"The optional `max_mkt_sz` field (maximum market-order size) is converted to a `Quantity`, and the string failed to parse. The field is optional: empty means None and no error; only a present-but-invalid value throws. This guards against a corrupted market-order size limit entering the instrument definition.","triggerScenarios":"parse_common_instrument_data receives an OkxInstrumentDef with a non-empty max_mkt_sz that Quantity::from_str cannot parse (bad decimal, scientific notation, placeholder text) — typically from a malformed API payload or edited fixture.","commonSituations":"OKX returning placeholder or corrupted values for rarely-used fields; hand-built test fixtures; version drift between cached snapshots and the current parser expectations.","solutions":["Inspect definition.max_mkt_sz for the failing inst_id; verify it is a plain decimal string.","Confirm the value matches the OKX instruments API response for that instId.","Fix the source data (fixture/cache); if the exchange value is genuinely unusable, clear the field so it parses as None.","Trim/normalize the string (e.g. strip whitespace or units) before parsing if that is the failure cause."],"exampleFix":"// before\nSome(Quantity::from_str(&definition.max_mkt_sz).map_err(|e| ...)?)\n// after\nlet v = definition.max_mkt_sz.trim();\nSome(Quantity::from_str(v).map_err(|e| ...)?)","handlingStrategy":"validation","validationCode":"// max_mkt_sz is optional: empty is fine, only validate when present\nfn valid_optional_decimal(s: &str) -> bool {\n    let t = s.trim();\n    t.is_empty() || t.parse::<f64>().is_ok()\n}\nassert!(valid_optional_decimal(&definition.max_mkt_sz), \"bad max_mkt_sz\");","typeGuard":"fn optional_quantity(s: &str) -> Option<&str> {\n    let t = s.trim();\n    if t.is_empty() { None } else if t.parse::<f64>().is_ok() { Some(t) } else { None }\n}","tryCatchPattern":"match parse_instrument_with_parser(&definition, ts_init) {\n    Ok(inst) => inst,\n    Err(e) if e.to_string().contains(\"max_mkt_sz\") => {\n        tracing::warn!(inst_id = %definition.inst_id, \"bad max_mkt_sz; continuing without limit: {e}\");\n        continue;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat optional fields as optional end-to-end: empty string -> None, never \"0\" placeholders.","Validate only when the field is non-empty.","Refresh cached instrument snapshots when OKX schema versions change.","Include the raw failing value and inst_id in error logs."],"tags":["okx","instrument-parsing","quantity-parse","optional-field"],"backgroundTag":"invalid-argument-format","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"}