nautechsystems/nautilus_trader · error · anyhow::Error

Invalid IBOrderTags field {field}: {e}

Error message

Invalid IBOrderTags field {field}: {e}

What it means

The IBOrderTags overlay mechanism validates each field name against the known IBOrderTags schema before applying an update to an ib_order JSON representation. When apply_order_field_update receives a field name the schema does not recognize (or the value fails field-level validation, error `e`), it rolls the order object back to its previous state and returns this error. The overlay is rejected wholesale so a partially-applied tag set is never sent to IB.

Source

Thrown at crates/adapters/interactive_brokers/src/execution/transform/tags.rs:127

    let previous = order_obj.insert(field.to_string(), value);

    match serde_json::from_value::<IBOrder>(order_value.clone()) {
        Ok(updated_order) => {
            *ib_order = updated_order;
            Ok(())
        }
        Err(e) => {
            let Some(order_obj) = order_value.as_object_mut() else {
                anyhow::bail!(
                    "Failed to restore IB order JSON after invalid IBOrderTags field: {field}"
                );
            };

            match previous {
                Some(previous) => order_obj.insert(field.to_string(), previous),
                None => order_obj.remove(field),
            };
            Err(anyhow::anyhow!("Invalid IBOrderTags field {field}: {e}"))
        }
    }
}

fn sync_order_field(
    order_value: &mut Value,
    field: &str,
    ib_order: &IBOrder,
) -> anyhow::Result<()> {
    let updated_order_value = serde_json::to_value(ib_order).with_context(|| {
        format!("Failed to serialize IB order after applying IBOrderTags field: {field}")
    })?;

    let Some(updated_field_value) = updated_order_value.get(field).cloned() else {
        return Ok(());
    };

    if let Some(order_obj) = order_value.as_object_mut() {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Correct the field name in the IBOrderTags input to one of the supported schema fields.
  2. Check the wrapped error `e` in the message to see which value failed validation for a known field and fix its format.
  3. Align the adapter version producing the tags with the version applying them so both share the same schema.
  4. Validate the tags JSON against the IBOrderTags schema locally before applying the overlay.

Example fix

// before
let tags = r#"{ "trailType": "abs" }"#; // unknown field
// after
let tags = r#"{ "order_type": "TRAIL" }"#; // valid IBOrderTags field
Defensive patterns

Strategy: validation

Validate before calling

// validate keys against known IBOrderTags fields before overlay
for key in tags_map.keys() {
    assert!(SUPPORTED_IB_ORDER_TAG_FIELDS.contains(&key.as_str()), "unknown IBOrderTags field: {key}");
}

Try / catch

match apply_ib_order_tag_overlay(&mut order, &tags) {
    Ok(()) => (),
    Err(e) if e.to_string().contains("Invalid IBOrderTags field") => {
        log::warn!("dropping invalid tags: {e}"); // order left unchanged by rollback
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling apply_ib_order_tag_overlay with an IBOrderTags map containing a key not in the IBOrderTags field enum/schema, or a value that fails parsing/validation for a known field (the wrapped `e`).

Common situations: Typo in a tag key in an order-tags config/JSON payload; a tag added by a newer/older adapter version that the schema does not know; pasting tags from documentation for a different adapter.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/58f68646cb4e742f. Report an issue: GitHub.