{"record":{"id":"e671a722615f627d","repo":"nautechsystems/nautilus_trader","slug":"failed-to-convert-trailing-offset-trailing-offset","errorCode":null,"errorMessage":"Failed to convert trailing offset {trailing_offset} to f64: {e}","messagePattern":"Failed to convert trailing offset (.+?) to f64: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/transform/policy.rs","lineNumber":77,"sourceCode":"    }\n    Ok(())\n}\n\npub(super) fn apply_trailing_order_policy(\n    ib_order: &mut IBOrder,\n    order: &OrderAny,\n    price_magnifier: f64,\n) -> anyhow::Result<()> {\n    if !matches!(\n        order.order_type(),\n        NautilusOrderType::TrailingStopMarket | NautilusOrderType::TrailingStopLimit\n    ) {\n        return Ok(());\n    }\n\n    if let Some(trailing_offset) = order.trailing_offset() {\n        let trailing_offset_f64 = trailing_offset.to_string().parse::<f64>().map_err(|e| {\n            anyhow::anyhow!(\"Failed to convert trailing offset {trailing_offset} to f64: {e}\")\n        })?;\n\n        match order.trailing_offset_type() {\n            Some(TrailingOffsetType::BasisPoints) => {\n                ib_order.trailing_percent = Some(trailing_offset_f64 / 100.0);\n            }\n            Some(TrailingOffsetType::Price) | None => {\n                ib_order.aux_price = Some(trailing_offset_f64);\n            }\n            Some(other) => anyhow::bail!(\"`TrailingOffsetType` {:?} is not supported\", other),\n        }\n    }\n\n    if let Some(trigger_price) = order.trigger_price() {\n        let converted_trigger = convert_price(trigger_price, price_magnifier);\n        ib_order.trail_stop_price = Some(converted_trigger);\n        ib_order.trigger_method = order\n            .trigger_type()","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/transform/policy.rs#L59-L95","documentation":"The IB adapter converts an order's trailing offset (a domain Money/quantity-like value) to an f64 to populate IB's trailing amount/percent fields. The string representation of the trailing offset could not be parsed as f64, so the order transform aborts before the order is sent to Interactive Brokers. This indicates the trailing offset value is malformed or in an unexpected textual format.","triggerScenarios":"Calling nautilus_order_to_ib_order on a TRAILING_STOP or TRAILING_STOP_MARKET order whose trailing_offset() returns Some(value) where value.to_string() is not parseable as f64 (e.g. contains formatting characters, commas, or is a non-numeric domain value).","commonSituations":"Constructing trailing-stop orders with offsets built from unusual custom types or regions whose Display output is not a plain decimal; localizations or custom wrappers that emit thousands separators; passing a percentage value wrapped in extra characters.","solutions":["Check the order's trailing offset value before submission; ensure it is created from a plain decimal (e.g. Price/Decimal from a numeric literal, not a formatted string).","Log or print the offending trailing offset shown in the message to see the exact unparseable text.","If using a custom Money/Quantity-like type, make sure its Display impl outputs a bare decimal number.","Upgrade the adapter/domain crates together so trailing_offset() returns a type whose string form is numeric."],"exampleFix":"// before\nlet offset = Price::from(\"1,25.5\"); // formatted string, unparseable\n// after\nlet offset = Price::from(125.5); // plain decimal","handlingStrategy":"validation","validationCode":"if let Some(offset) = order.trailing_offset() {\n    let s = offset.to_string();\n    if s.parse::<f64>().is_err() {\n        panic!(\"trailing offset not numeric: {s}\");\n    }\n}","typeGuard":"fn is_numeric_offset(offset: &impl std::fmt::Display) -> bool {\n    offset.to_string().parse::<f64>().is_ok()\n}","tryCatchPattern":null,"preventionTips":["Create trailing offsets from plain decimals, never from formatted strings","Unit-test order construction with trailing offsets before live submission","Assert Display output of custom offset types is a bare number"],"tags":["order-submission","parse","trailing-stop"],"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"}