nautechsystems/nautilus_trader · error

TrailingStopMarket requires trailing_offset

Error message

TrailingStopMarket requires trailing_offset

What it means

submit_conditional_order for an OKX TrailingStopMarket order requires a trailing_offset (the activation callback distance). When the command arrives without it, the adapter cannot compute OKX's callback_ratio or callback_spread and rejects the submission immediately. This mirrors the fact that OKX trailing orders must carry an activation offset.

Source

Thrown at crates/adapters/okx/src/execution.rs:891

        let trigger_type = context.trigger_type;
        let trigger_price = context.trigger_price;
        let price = context.price;
        let is_reduce_only = context.is_reduce_only;

        let trailing_offset = order.trailing_offset();
        let trailing_offset_type = order.trailing_offset_type();
        let activation_price = order.activation_price();

        let close_fraction = get_param_as_string(&cmd.params, "close_fraction");
        let reduce_only = if close_fraction.is_some() {
            Some(true)
        } else {
            Some(is_reduce_only)
        };

        let (callback_ratio, callback_spread) = if order_type == OrderType::TrailingStopMarket {
            let offset = trailing_offset
                .ok_or_else(|| anyhow::anyhow!("TrailingStopMarket requires trailing_offset"))?;
            let offset_type = trailing_offset_type.ok_or_else(|| {
                anyhow::anyhow!("TrailingStopMarket requires trailing_offset_type")
            })?;

            match offset_type {
                TrailingOffsetType::BasisPoints => {
                    // Convert basis points to ratio (e.g., 100 bps = 0.01)
                    let ratio = offset / Decimal::from(10000);
                    (Some(ratio.to_string()), None)
                }
                TrailingOffsetType::Price => (None, Some(offset.to_string())),
                _ => {
                    anyhow::bail!("Unsupported trailing_offset_type for OKX: {offset_type:?}");
                }
            }
        } else {
            (None, None)
        };

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Set trailing_offset on the order command before submitting a TrailingStopMarket order.
  2. Also set trailing_offset_type (see error 3457) — both are required for this order type.
  3. Validate at strategy level: raise a user error early if order type is trailing but offset is missing.
  4. Switch to a non-trailing order type if you did not intend a trailing stop.

Example fix

// before
let order = order_factory.market(
    instrument_id, OrderSide::Sell, quantity,
); // submitted as TrailingStopMarket
// after
let order = order_factory.trailing_stop_market(
    instrument_id, OrderSide::Sell, quantity,
    Decimal::from(1),           // trailing_offset
    TrailingOffsetType::BasisPoints,
);
Defensive patterns

Strategy: validation

Validate before calling

if order_type == OrderType::TrailingStopMarket
    && (trailing_offset.is_none() || trailing_offset_type.is_none()) {
    return Err(anyhow::anyhow!(
        "TrailingStopMarket requires trailing_offset and trailing_offset_type"
    ));
}

Type guard

fn trailing_params_valid(
    trailing_offset: Option<Decimal>,
    trailing_offset_type: Option<TrailingOffsetType>,
) -> bool {
    trailing_offset.is_some() && trailing_offset_type.is_some()
}

Prevention

When it happens

Trigger: Calling submit_order with order_type == TrailingStopMarket on the OKX execution client while leaving the order command's trailing_offset unset (None).

Common situations: Strategy code building SubmitOrder without setting trailing_offset; orders translated from another adapter where offset was optional; UI/backtest configs omitting the trailing parameters; migrating strategy code between order types without updating parameters.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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