{"record":{"id":"02522ae99b44ace1","repo":"nautechsystems/nautilus_trader","slug":"trigger-price-required-for-order-type","errorCode":null,"errorMessage":"trigger_price required for {order_type:?}","messagePattern":"trigger_price required for (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/http/parse.rs","lineNumber":242,"sourceCode":"/// based on order type and side.\n///\n/// # Errors\n///\n/// Returns an error if:\n/// - Conditional order is missing trigger price.\n/// - Trigger price is on wrong side of limit price for the order type.\npub fn validate_conditional_order(\n    order_type: DydxOrderType,\n    trigger_price: Option<Decimal>,\n    price: Decimal,\n    side: OrderSide,\n) -> anyhow::Result<()> {\n    if !order_type.is_conditional() {\n        return Ok(());\n    }\n\n    let trigger_price = trigger_price\n        .ok_or_else(|| anyhow::anyhow!(\"trigger_price required for {order_type:?}\"))?;\n\n    // Validate trigger price relative to limit price\n    match order_type {\n        DydxOrderType::StopLimit | DydxOrderType::StopMarket => {\n            // Stop orders: trigger when price falls (sell) or rises (buy)\n            match side {\n                OrderSide::Buy if trigger_price < price => {\n                    anyhow::bail!(\n                        \"Stop buy trigger_price ({trigger_price}) must be >= limit price ({price})\"\n                    );\n                }\n                OrderSide::Sell if trigger_price > price => {\n                    anyhow::bail!(\n                        \"Stop sell trigger_price ({trigger_price}) must be <= limit price ({price})\"\n                    );\n                }\n                _ => {}\n            }","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/http/parse.rs#L224-L260","documentation":"dYdX conditional order types (STOP_LIMIT, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET) require a trigger price that the validator checks against the limit price and side. validate_conditional_order throws this when a conditional order is submitted without a trigger_price parameter. It is a fail-fast guard before the order reaches the exchange.","triggerScenarios":"Calling validate_conditional_order (or placing an order through it) with order_type.is_conditional() true but the trigger_price Option set to None.","commonSituations":"Submitting a stop or take-profit order while omitting the trigger_price field; code paths that build conditional orders conditionally and skip trigger price on some branches; porting market/limit order code to conditional types without adding trigger price.","solutions":["Provide the trigger_price argument when submitting any stop or take-profit (conditional) order type","Check order_type first: only conditional types need trigger_price; non-conditional types return Ok early","Use a validation helper or builder that makes trigger_price required for conditional order constructors","Add a unit test mirroring test_validate_stop_limit_buy_invalid to catch missing trigger_price"],"exampleFix":"// before\nsubmit_order(OrderType::StopMarket, side, quantity, price, None /* trigger_price */);\n// after\nsubmit_order(OrderType::StopMarket, side, quantity, price, Some(trigger_price));","handlingStrategy":"validation","validationCode":"if order_type.is_conditional() && trigger_price.is_none() {\n    return Err(anyhow!(\"trigger_price required for {order_type:?}\"));\n}\nvalidate_conditional_order(order_type, side, trigger_price, limit_price)?;","typeGuard":"fn conditional_ready(t: DydxOrderType, tp: Option<Price>) -> bool {\n    !t.is_conditional() || tp.is_some()\n}","tryCatchPattern":"match validate_conditional_order(...) {\n    Err(e) if e.to_string().contains(\"trigger_price required\") => {\n        eprintln!(\"Supply trigger_price for {order_type:?}\");\n    }\n    Err(e) => return Err(e),\n    Ok(()) => submit(),\n}","preventionTips":["Make trigger_price a required constructor field for conditional order builders","Branch on order_type.is_conditional() before composing order submission args","Add unit tests for each conditional order type mirroring the existing test suite"],"tags":["rust","dydx","orders","validation"],"backgroundTag":"missing-required-argument","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"}