{"record":{"id":"850caf289ac28365","repo":"nautechsystems/nautilus_trader","slug":"e-850caf","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/http/client.rs","lineNumber":2362,"sourceCode":"        let mut params = SetPositionModeParamsBuilder::default();\n        params.pos_mode(position_mode);\n        let params = params.build().map_err(|e| anyhow::anyhow!(e))?;\n\n        match self.inner.set_position_mode(params).await {\n            Ok(_) => Ok(()),\n            Err(e) => {\n                if let OKXHttpError::OkxError {\n                    error_code,\n                    message,\n                } = &e\n                    && error_code == \"50115\"\n                {\n                    log::warn!(\n                        \"Account does not support position mode setting (derivatives trading not enabled): {message}\"\n                    );\n                    return Ok(()); // Gracefully handle this case\n                }\n                anyhow::bail!(e)\n            }\n        }\n    }\n\n    /// Requests all instruments for the `instrument_type` from OKX.\n    ///\n    /// Option requests require `instrument_family` (OKX `instFamily`), for example `BTC-USD`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if `instrument_type` is option and `instrument_family` is missing,\n    /// the HTTP request fails, or instrument parsing fails.\n    ///\n    /// # Returns\n    ///\n    /// A tuple containing:\n    /// - `Vec<InstrumentAny>`: The parsed instruments\n    /// - `Vec<(Ustr, u64)>`: Mappings of inst_id to inst_id_code for WebSocket order operations","sourceCodeStart":2344,"sourceCodeEnd":2380,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/http/client.rs#L2344-L2380","documentation":"In the OKX HTTP client's set-position-mode call, certain OKX error codes (indicating derivatives trading is not enabled on the account) are handled gracefully with a warning and Ok. Any other error is re-raised verbatim with anyhow::bail!(e). The message is therefore the raw OKX API error text, surfacing whatever the exchange returned for the position-mode request.","triggerScenarios":"Calling the client method that sets position mode when OKX rejects it for a reason other than 'derivatives not enabled' — e.g. open positions exist, invalid posMode value, or account-level restrictions.","commonSituations":"Configuring an adapter for an account without derivatives enabled yet requesting a hedge/net mode change; having open positions that block the mode switch; sending a posMode value OKX no longer accepts.","solutions":["Read the embedded OKX message to identify the API error and address it at the exchange level (close positions, enable derivatives, use a valid posMode)","Enable derivatives trading on the OKX account or skip position-mode configuration for such accounts","Verify the posMode parameter matches one of OKX's allowed values (long_short_mode / net_mode)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Check account derivatives capability before setting position mode\n// (query account config first and skip the call if derivatives are not enabled)","typeGuard":null,"tryCatchPattern":"match client.set_position_mode(mode).await {\n    Ok(()) => {},\n    Err(e) => {\n        // message is the raw OKX error text; inspect it and decide\n        log::warn!(\"position mode not applied: {e}\");\n    }\n}","preventionTips":["Enable derivatives trading on the OKX account before configuring position mode","Do not set position mode while positions are open","Match posMode to one of OKX's accepted values (long_short_mode / net_mode)"],"tags":["okx","http","api-error","position-mode"],"backgroundTag":"api-error-response","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"}