{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":2551,"sourceCode":"            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(|p| p.get_bool(\"close_position\"))\n            .unwrap_or(false);\n\n        if close_position {\n            let order_type = order.order_type();\n\n            if !matches!(\n                order_type,\n                OrderType::StopMarket | OrderType::MarketIfTouched\n            ) {\n                anyhow::bail!(\n                    \"`close_position` is not supported for order type {order_type:?} on Binance\"\n                );\n            }\n\n            if order.is_reduce_only() {\n                anyhow::bail!(\"`close_position` cannot be combined with `reduce_only` on Binance\");\n            }\n        }\n\n        if let Some(pm_str) = cmd.params.as_ref().and_then(|p| p.get_str(\"price_match\")) {\n            BinancePriceMatch::from_param(pm_str)?;\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\"\n            );\n            anyhow::ensure!(\n                order_type == OrderType::Limit,","sourceCodeStart":2533,"sourceCodeEnd":2569,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/execution.rs#L2533-L2569","documentation":"The close_position parameter (closePosition=1) asks Binance Futures to close the entire position when the order triggers; the venue only accepts it on STOP_MARKET and MARKET_IF_TOUCHED orders. The adapter enforces this before submission and rejects any other order type (LIMIT, MARKET, STOP_LIMIT, TRAILING_STOP_MARKET) with this message.","triggerScenarios":"SubmitOrder with params containing close_position=true on an order whose type is not StopMarket or MarketIfTouched.","commonSituations":"Close-all logic written for one order type and reused on another; porting from adapters or venues where close_position applies more broadly.","solutions":["Use a STOP_MARKET or MARKET_IF_TOUCHED order (with a trigger price) when setting close_position=true","Alternatively drop close_position and send a reduce-only order sized to the current position","For immediate liquidation use a plain MARKET order with quantity equal to the position size"],"exampleFix":"// before — close_position on a LIMIT order (rejected locally)\n// params: close_position = true; order_type = OrderType::Limit\n\n// after — close_position only on trigger order types\n// params: close_position = true; order_type = OrderType::StopMarket with trigger price set","handlingStrategy":"validation","validationCode":"// Before submit_order() with close_position\nlet close_position = params.get_bool(\"close_position\").unwrap_or(false);\nif close_position {\n    assert!(\n        matches!(order.order_type(), OrderType::StopMarket | OrderType::MarketIfTouched),\n        \"close_position requires STOP_MARKET or MARKET_IF_TOUCHED\"\n    );\n}","typeGuard":"fn close_position_combinable(order: &OrderAny, close_position: bool) -> bool {\n    !close_position\n        || matches!(order.order_type(), OrderType::StopMarket | OrderType::MarketIfTouched)\n}","tryCatchPattern":"Handle the submit_order error (or resulting denied/rejected order event) by rebuilding the order as STOP_MARKET/MARKET_IF_TOUCHED or removing the close_position param, then resubmitting.","preventionTips":["Centralize close-position order creation in one factory that pins the order type","Assert order type and param compatibility in strategy unit tests","Review parameter templates when porting close logic between venues"],"tags":["binance","futures","close-position","order-validation","rust"],"backgroundTag":"unsupported-order-parameter","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}