{"record":{"id":"dc3c0738ab0cc58d","repo":"nautechsystems/nautilus_trader","slug":"close-position-requires-reduce-only-true-on-th","errorCode":null,"errorMessage":"`close_position` requires `reduce_only=true` on the Nautilus order","messagePattern":"`close_position` requires `reduce_only=true` on the Nautilus order","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":3658,"sourceCode":"        anyhow::ensure!(\n            offset_type == TrailingOffsetType::BasisPoints,\n            \"Binance only supports TrailingOffsetType::BasisPoints, received {offset_type:?}\"\n        );\n\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)?;","sourceCodeStart":3640,"sourceCodeEnd":3676,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L3640-L3676","documentation":"Binance's `closePosition=true` parameter closes an entire position with a market-style algo order and inherently reduces exposure, so the adapter requires the Nautilus order to be flagged `reduce_only`. If the `close_position` param is set in `SubmitOrder` params but the order itself is not reduce-only, validation fails to prevent a contradictory or rejected-by-venue request.","triggerScenarios":"Calling `submit_order` on a BinanceFuturesExecutionClient with `params.close_position = true` while the order was constructed without `reduce_only=true` (e.g. `OrderFactory::market(..., reduce_only=false)` or default factory settings).","commonSituations":"Adding the `close_position` param as an afterthought to an existing order builder call; copying an order template where reduce_only was not set; confusion between Binance-side closePosition and the Nautilus reduce_only flag.","solutions":["Rebuild the order with `reduce_only=true` (e.g. pass `reduce_only=true` to the OrderFactory method).","Alternatively remove the `close_position` param if full-position close is not intended.","Check that the account is not in hedge mode in a way that conflicts with reduce-only semantics, and that the position side matches."],"exampleFix":"// before\nlet order = factory.market(if_long(BUY, SELL), quantity);\nsubmit_order(order, Some(params_with_close_position()));\n// after\nlet order = factory.market(if_long(BUY, SELL), quantity, None, TimeInForce::Gtc, None,\n    /*reduce_only=*/ true);\nsubmit_order(order, Some(params_with_close_position()));","handlingStrategy":"validation","validationCode":"fn check_close_position(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 && !order.is_reduce_only() {\n        return Err(\"close_position=true requires reduce_only order\".into());\n    }\n    Ok(())\n}","typeGuard":"fn is_valid_close_position(order: &OrderAny, params: &Option<NautilusParams>) -> bool {\n    params.as_ref().and_then(|p| p.get_bool(\"close_position\")).unwrap_or(false)\n        .implies(|| order.is_reduce_only())\n}","tryCatchPattern":"match client.submit_order(cmd).await {\n    Err(e) if e.to_string().contains(\"close_position`) requires\") => {\n        // rebuild order with reduce_only=true or drop the param\n    }\n    other => other?,\n}","preventionTips":["Always set reduce_only=true whenever you pass close_position=true.","Keep close_position params next to the order factory call, not in a detached config.","Remember Nautilus reduce_only and Binance closePosition are separate flags that must agree."],"tags":["binance","close-position","reduce-only","order-validation"],"backgroundTag":"conflicting-config-options","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"}