{"record":{"id":"94a1b8d88083b8b3","repo":"nautechsystems/nautilus_trader","slug":"unapplied-cfd-swap-total-overflow","errorCode":null,"errorMessage":"unapplied CFD swap total overflow","messagePattern":"unapplied CFD swap total overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/backtest/src/modules/cfd_swap.rs","lineNumber":505,"sourceCode":"                AccountAdjustmentOutcome::Failed(error) if error.is_retryable() => {\n                    log::warn!(\n                        \"Cannot apply CFD swap adjustment for {} on {}: {error}\",\n                        adjustment.amount.currency,\n                        adjustment.booking_date\n                    );\n                    failed.push(adjustment);\n                }\n                AccountAdjustmentOutcome::Failed(error) => {\n                    log::warn!(\n                        \"CFD swap adjustment {} on {} is recorded as unapplied: {error}\",\n                        adjustment.amount,\n                        adjustment.booking_date\n                    );\n                    let mut totals = self.unapplied_swap_totals.borrow_mut();\n                    let total = totals.entry(adjustment.amount.currency).or_default();\n                    *total = total\n                        .checked_add(adjustment.amount.as_decimal())\n                        .ok_or_else(|| anyhow::anyhow!(\"unapplied CFD swap total overflow\"))?;\n                }\n            }\n        }\n\n        let mut day = self.rollover_day.borrow_mut();\n        let day = day\n            .as_mut()\n            .ok_or_else(|| anyhow::anyhow!(\"CFD swap rollover day is not initialized\"))?;\n        if failed.is_empty() {\n            day.date = batch_end_date;\n            day.pending_end_date = None;\n            day.warned_failures.clear();\n            self.rollover_completed.set(true);\n        } else {\n            day.pending_adjustments = Some(failed);\n        }\n        Ok(())\n    }","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/modules/cfd_swap.rs#L487-L523","documentation":"Raised when accumulating a failed (non-retryable) CFD swap adjustment amount into the per-currency `unapplied_swap_totals` diagnostic would overflow. Like the applied-total overflow, it protects the integrity of diagnostic aggregation for swap adjustments that could not be applied.","triggerScenarios":"Many failed swap adjustments (e.g. persistent account/funding errors) whose summed amounts exceed the Decimal accumulator bound during a backtest.","commonSituations":"Long backtests where every rollover fails (e.g. account currency never funded, missing rate data) so unapplied amounts pile up daily; corrupted amount data inflating each adjustment.","solutions":["Fix the root cause making adjustments fail (funding, account config, rate data) so failures stop accumulating.","Run a shorter backtest window or reset diagnostics periodically.","Validate input amounts and account currencies before starting the run."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"anyhow::ensure!(account.is_funded_for(currency), \"account must hold {currency} before swaps accrue\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = engine.acknowledge(&outcomes) {\n    if e.to_string().contains(\"unapplied CFD swap total overflow\") {\n        log::error!(\"too many failed adjustments accumulated; fix underlying failures\");\n    } else { return Err(e); }\n}","preventionTips":["Fix the root causes of failed adjustments early (funding, currencies, rate data)","Monitor failed-adjustment counts during the run instead of letting them accrue for the full window","Validate adjustment amounts against realistic bounds before the backtest"],"tags":["backtest","cfd","decimal-overflow","diagnostics"],"backgroundTag":"value-out-of-range","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"}