{"record":{"id":"69ed128a6423c8b2","repo":"nautechsystems/nautilus_trader","slug":"binance-user-trade-id-overflow-during-pagination","errorCode":null,"errorMessage":"Binance user trade ID overflow during pagination","messagePattern":"Binance user trade ID overflow during pagination","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":2563,"sourceCode":"\n                let page_len = page.len();\n                let max_trade_id = page.iter().map(|trade| trade.id).max().unwrap();\n                let passed_end = requested_end_time\n                    .is_some_and(|end_time| page.iter().any(|trade| trade.time > end_time));\n\n                trades.extend(page.into_iter().filter(|trade| {\n                    requested_end_time.is_none_or(|end_time| trade.time <= end_time)\n                        && seen_trade_ids.insert(trade.id)\n                }));\n\n                if page_len < USER_TRADES_PAGE_LIMIT as usize || passed_end {\n                    break;\n                }\n\n                let next_from_id = max_trade_id\n                    .checked_add(1)\n                    .context(\"Binance user trade ID overflow during pagination\")?;\n                anyhow::ensure!(\n                    next_from_id > from_id,\n                    \"Binance user-trades pagination made no progress\"\n                );\n                from_id = next_from_id;\n            }\n        }\n\n        trades.sort_unstable_by_key(|trade| (trade.time, trade.id));\n        let ts_init = self.clock.get_time_ns();\n\n        let mut reports = Vec::new();\n\n        for trade in trades {\n            let venue_position_id = make_venue_position_id(\n                self.config.use_position_ids,\n                instrument.id(),\n                trade.position_side,\n            )?;","sourceCodeStart":2545,"sourceCodeEnd":2581,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L2545-L2581","documentation":"The ID-based pagination path advances its cursor with `max_trade_id.checked_add(1)`. Binance trade IDs are i64; if the maximum ID on a page is i64::MAX the increment overflows, and `checked_add` returns None, producing this contextual error instead of a silent wraparound to a negative cursor.","triggerScenarios":"generate_fill_reports pagination receiving a page whose maximum Binance trade id equals i64::MAX (9223372036854775807), making cursor+1 unrepresentable.","commonSituations":"Essentially only with adversarial/mocked data or a hypothetical future where Binance IDs reach i64::MAX; real Binance trade IDs are far below this bound. Mostly seen in unit tests with fabricated IDs.","solutions":["If in tests, use realistic trade IDs well below i64::MAX in fixtures.","If hit in production, report/patch the adapter to use u64 or saturating arithmetic for the cursor.","Restart reconciliation after the problematic range so pagination starts from a lower cursor."],"exampleFix":"// before\nlet next_from_id = max_trade_id.checked_add(1).context(\"Binance user trade ID overflow during pagination\")?;\n// after (adapter-side patch)\nlet next_from_id = max_trade_id.saturating_add(1); // and break when saturated","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = client.generate_mass_status().await {\n    if e.to_string().contains(\"ID overflow\") {\n        error!(\"Binance trade ID overflow — adapter patch required\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Use realistic trade IDs in test fixtures (well below i64::MAX).","Track Binance API changes to trade ID formats.","Patch the adapter to use u64 cursors if IDs ever approach the limit."],"tags":["overflow","binance","pagination","integer"],"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"}