nautechsystems/nautilus_trader · error

SL override fields require 'stop_loss' to be set

Error message

SL override fields require 'stop_loss' to be set

What it means

parse_bybit_tp_sl_params validates SL/TP override params before building the Bybit tpsl-mode order payload. If any stop-loss override field (e.g. sl_order_type, sl_limit_price, sl_trigger_price) is present in the Params but no 'stop_loss' value itself was set, the parser bails because override fields are meaningless without the SL price they modify.

Source

Thrown at crates/adapters/bybit/src/common/parse.rs:1868

        result.tpsl_mode = Some(parse_tpsl_mode(s)?);
    }

    let has_tp_fields = result.tp_trigger_by.is_some()
        || result.tp_order_type.is_some()
        || result.tp_limit_price.is_some()
        || result.tp_trigger_price.is_some();

    let has_sl_fields = result.sl_trigger_by.is_some()
        || result.sl_order_type.is_some()
        || result.sl_limit_price.is_some()
        || result.sl_trigger_price.is_some();

    if result.take_profit.is_none() && has_tp_fields {
        anyhow::bail!("TP override fields require 'take_profit' to be set");
    }

    if result.stop_loss.is_none() && has_sl_fields {
        anyhow::bail!("SL override fields require 'stop_loss' to be set");
    }

    if result.tp_order_type == Some(BybitOrderType::Limit) && result.tp_limit_price.is_none() {
        anyhow::bail!("'tp_order_type' is 'Limit' but 'tp_limit_price' was not provided");
    }

    if result.sl_order_type == Some(BybitOrderType::Limit) && result.sl_limit_price.is_none() {
        anyhow::bail!("'sl_order_type' is 'Limit' but 'sl_limit_price' was not provided");
    }

    if result.tp_limit_price.is_some() && result.tp_order_type != Some(BybitOrderType::Limit) {
        anyhow::bail!("'tp_limit_price' requires 'tp_order_type' to be 'Limit'");
    }

    if result.sl_limit_price.is_some() && result.sl_order_type != Some(BybitOrderType::Limit) {
        anyhow::bail!("'sl_limit_price' requires 'sl_order_type' to be 'Limit'");
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass a 'stop_loss' value in the params alongside any 'sl_*' override fields
  2. If the SL override fields were added unintentionally, remove them from params
  3. Check upstream code that constructs the Params to ensure stop_loss is not filtered out or renamed

Example fix

// before
let params = Params::new()
    .set("sl_order_type", "Limit")
    .set("sl_limit_price", "41000");
// after
let params = Params::new()
    .set("stop_loss", "42000")
    .set("sl_order_type", "Limit")
    .set("sl_limit_price", "41000");
Defensive patterns

Strategy: validation

Validate before calling

fn validate_sl_params(params: &Params) -> Result<(), String> {
    let has_sl_fields = ["sl_order_type", "sl_limit_price", "sl_trigger_price"]
        .iter().any(|k| params.get(k).is_some());
    if has_sl_fields && params.get("stop_loss").is_none() {
        return Err("SL override fields present but 'stop_loss' missing".into());
    }
    Ok(())
}

Type guard

fn requires_stop_loss(params: &Params) -> bool {
    ["sl_order_type", "sl_limit_price", "sl_trigger_price"]
        .iter().any(|k| params.get(k).is_some())
}

Try / catch

match parse_bybit_tp_sl_params(&params) {
    Ok(p) => submit(p),
    Err(e) if e.to_string().contains("'stop_loss' to be set") => {
        log::warn("SL override fields without stop_loss; supply stop_loss or drop sl_* fields");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling the TP/SL params parser with params containing keys like 'sl_order_type' or 'sl_limit_price' while 'stop_loss' is absent or None.

Common situations: Building a TP/SL modify request where the developer sets the SL order type or limit price but forgets to pass the stop_loss price; template/config-driven params where stop_loss is dropped by an upstream filter.

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/9d98c790f04708c6. Report an issue: GitHub.