{"record":{"id":"d39366e2818bb3b4","repo":"nautechsystems/nautilus_trader","slug":"lighter-execution-client-cannot-update-leverage-wi","errorCode":null,"errorMessage":"Lighter execution client cannot update leverage without credentials","messagePattern":"Lighter execution client cannot update leverage without credentials","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/execution.rs","lineNumber":2076,"sourceCode":"    ///\n    /// Nautilus does not expose a `set_leverage` command on the execution\n    /// trait, so this method is callable directly from strategy or bootstrap\n    /// code.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if credentials are missing, the instrument is not\n    /// registered, `initial_margin_fraction` is outside `1..=10_000`, or\n    /// the dispatch pre-flight (nonce allocation, signing) fails. Transport\n    /// errors after dispatch are logged but not returned synchronously.\n    pub fn update_leverage(\n        &self,\n        instrument_id: InstrumentId,\n        initial_margin_fraction: u16,\n        margin_mode: LighterPositionMarginMode,\n    ) -> anyhow::Result<()> {\n        let credential = self.credential.as_ref().ok_or_else(|| {\n            anyhow::anyhow!(\"Lighter execution client cannot update leverage without credentials\")\n        })?;\n\n        let market_index = self.registry.market_index(&instrument_id).ok_or_else(|| {\n            anyhow::anyhow!(\"no Lighter market_index registered for instrument {instrument_id}\")\n        })?;\n\n        anyhow::ensure!(\n            (1..=10_000).contains(&initial_margin_fraction),\n            \"initial_margin_fraction must be in 1..=10_000, was {initial_margin_fraction}\",\n        );\n\n        let ReservedTxContext {\n            context,\n            mut send_reservation,\n        } = self.build_tx_context(credential)?;\n\n        let connection_epoch = send_reservation.connection_epoch;\n","sourceCodeStart":2058,"sourceCodeEnd":2094,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/execution.rs#L2058-L2094","documentation":"Updating leverage on Lighter is a signed transaction that requires API credentials (account key). The execution client holds an optional credential; if it was never configured, update_leverage refuses rather than attempting an unsigned request that the venue would reject.","triggerScenarios":"Calling execution_client.update_leverage(instrument_id, initial_margin_fraction, margin_mode) on a client constructed without API key/credential (e.g. market-data-style or read-only configuration).","commonSituations":"Adapter configured with only a public/signing-less setup; credentials provided to the data client but not the execution client; env vars for the API key missing at startup; key rotation left the client credential=None.","solutions":["Configure the Lighter execution client with API credentials (api key/private key) before calling update_leverage.","Verify the same credential source used for signing orders is wired into this client instance.","Check environment/config (e.g. LIGHTER_API_KEY or equivalent) is present and loaded at client construction."],"exampleFix":"// before\nlet client = LighterExecutionClient::builder().instrument_provider(provider).build()?;\n// after\nlet client = LighterExecutionClient::builder()\n    .instrument_provider(provider)\n    .credential(credential) // api key + private key\n    .build()?;","handlingStrategy":"validation","validationCode":"if client.credential().is_none() {\n    return Err(\"configure Lighter API credentials before update_leverage\".into());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.update_leverage(iid, imf, mode).await {\n    if e.to_string().contains(\"without credentials\") {\n        // rebuild client with credentials or surface config error to operator\n    }\n}","preventionTips":["Load and validate credentials at startup; fail fast if absent for execution clients.","Keep data-client and execution-client credential wiring symmetric.","Check env/config keys with a startup assertion, not at first API call."],"tags":["credentials","leverage","authentication","lighter"],"backgroundTag":"missing-credentials","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"}