{"record":{"id":"a3bc256c31bba694","repo":"nautechsystems/nautilus_trader","slug":"close-position-is-not-supported-for-order-type","errorCode":null,"errorMessage":"`close_position` is not supported for order type {order_type:?} on Binance","messagePattern":"`close_position` is not supported for order type (.+?) on Binance","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":3662,"sourceCode":"\n        if let Some(offset) = order.trailing_offset() {\n            trailing_offset_to_callback_rate(offset)?;\n        }\n    }\n\n    let close_position = cmd\n        .params\n        .as_ref()\n        .and_then(|params| params.get_bool(PARAMS_CLOSE_POSITION))\n        .unwrap_or(false);\n\n    if close_position {\n        let order_type = order.order_type();\n        anyhow::ensure!(\n            order.is_reduce_only(),\n            \"`close_position` requires `reduce_only=true` on the Nautilus order\"\n        );\n        anyhow::ensure!(\n            matches!(\n                order_type,\n                OrderType::StopMarket | OrderType::MarketIfTouched\n            ),\n            \"`close_position` is not supported for order type {order_type:?} on Binance\"\n        );\n    }\n\n    if let Some(price_match) = cmd\n        .params\n        .as_ref()\n        .and_then(|params| params.get_str(\"price_match\"))\n    {\n        BinancePriceMatch::from_param(price_match)?;\n        let order_type = order.order_type();\n        anyhow::ensure!(\n            !order.is_post_only(),\n            \"price_match cannot be combined with post-only orders\"","sourceCodeStart":3644,"sourceCodeEnd":3680,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L3644-L3680","documentation":"Binance's `closePosition` parameter is only valid for order types that can close a whole position with a trigger: `StopMarket` and `MarketIfTouched`. When `close_position=true` is set in params and the order type is anything else (Limit, Market, StopLimit, LimitIfTouched, etc.), validation rejects the request before it reaches the venue.","triggerScenarios":"Submitting an order with `params.close_position=true` and an `order_type()` of `Limit`, `Market`, `StopLimit`, or `LimitIfTouched` on a BinanceFuturesExecutionClient.","commonSituations":"Attaching `close_position` to a generic order builder whose type was later changed; trying to close a position with a stop-limit (Binance requires STOP_MARKET or TAKE_PROFIT_MARKET semantics); template reuse across order types.","solutions":["Use `OrderType::StopMarket` or `OrderType::MarketIfTouched` when `close_position=true` is set.","Remove the `close_position` param and use a normal reduce-only order for other order types.","For stop-limit style exits, drop close_position and instead set `reduce_only=true` with an explicit quantity."],"exampleFix":"// before\nlet order = factory.stop_limit(...); // + params close_position=true\n// after\nlet order = factory.stop_market(...); // params close_position=true, reduce_only=true","handlingStrategy":"validation","validationCode":"fn check_close_position_type(order: &OrderAny, params: &Option<NautilusParams>) -> Result<(), String> {\n    let close = params.as_ref()\n        .and_then(|p| p.get_bool(\"close_position\"))\n        .unwrap_or(false);\n    if close && !matches!(order.order_type(), OrderType::StopMarket | OrderType::MarketIfTouched) {\n        return Err(format!(\"close_position unsupported for {:?}\", order.order_type()));\n    }\n    Ok(())\n}","typeGuard":"fn supports_close_position(t: OrderType) -> bool {\n    matches!(t, OrderType::StopMarket | OrderType::MarketIfTouched)\n}","tryCatchPattern":"match client.submit_order(cmd).await {\n    Err(e) if e.to_string().contains(\"not supported for order type\") => {\n        // switch to StopMarket/MarketIfTouched or drop close_position\n    }\n    other => other?,\n}","preventionTips":["Use close_position only with StopMarket or MarketIfTouched orders.","For other exit styles use reduce_only with explicit quantity instead.","Validate order-type/param combinations in a shared pre-submit checker."],"tags":["binance","close-position","order-type","order-validation"],"backgroundTag":"unsupported-operation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}