nautechsystems/nautilus_trader · error · anyhow::Error
Failed to convert trailing offset {trailing_offset} to f64:
Error message
Failed to convert trailing offset {trailing_offset} to f64: {e} What it means
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.
Source
Thrown at crates/adapters/interactive_brokers/src/execution/transform/policy.rs:77
}
Ok(())
}
pub(super) fn apply_trailing_order_policy(
ib_order: &mut IBOrder,
order: &OrderAny,
price_magnifier: f64,
) -> anyhow::Result<()> {
if !matches!(
order.order_type(),
NautilusOrderType::TrailingStopMarket | NautilusOrderType::TrailingStopLimit
) {
return Ok(());
}
if let Some(trailing_offset) = order.trailing_offset() {
let trailing_offset_f64 = trailing_offset.to_string().parse::<f64>().map_err(|e| {
anyhow::anyhow!("Failed to convert trailing offset {trailing_offset} to f64: {e}")
})?;
match order.trailing_offset_type() {
Some(TrailingOffsetType::BasisPoints) => {
ib_order.trailing_percent = Some(trailing_offset_f64 / 100.0);
}
Some(TrailingOffsetType::Price) | None => {
ib_order.aux_price = Some(trailing_offset_f64);
}
Some(other) => anyhow::bail!("`TrailingOffsetType` {:?} is not supported", other),
}
}
if let Some(trigger_price) = order.trigger_price() {
let converted_trigger = convert_price(trigger_price, price_magnifier);
ib_order.trail_stop_price = Some(converted_trigger);
ib_order.trigger_method = order
.trigger_type()View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let offset = Price::from("1,25.5"); // formatted string, unparseable
// after
let offset = Price::from(125.5); // plain decimal Defensive patterns
Strategy: validation
Validate before calling
if let Some(offset) = order.trailing_offset() {
let s = offset.to_string();
if s.parse::<f64>().is_err() {
panic!("trailing offset not numeric: {s}");
}
} Type guard
fn is_numeric_offset(offset: &impl std::fmt::Display) -> bool {
offset.to_string().parse::<f64>().is_ok()
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Kraken Spot trailing stops do not support activation trigger
- TrailingStopMarket requires trailing_offset
- TrailingStopMarket requires trailing_offset_type
- Unsupported `OrderSide` for Binance: {value:?}
- Invalid order side: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/e671a722615f627d.
Report an issue: GitHub.