{"record":{"id":"b0cc0146ebf8e0e1","repo":"nautechsystems/nautilus_trader","slug":"fill-maps-to-position-position-id-with-a-diff","errorCode":null,"errorMessage":"fill {} maps to position {position_id} with a different account or instrument","messagePattern":"fill (.+?) maps to position (.+?) with a different account or instrument","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/live/src/execution/manager.rs","lineNumber":2892,"sourceCode":"        if !hedge_context {\n            return Ok(PositionFillReportPreparation::Ready);\n        }\n\n        if report.venue_position_id.is_some() {\n            return Ok(PositionFillReportPreparation::Ready);\n        }\n\n        let Some(position_id) = mapped_position_id else {\n            return Ok(PositionFillReportPreparation::Unattributed);\n        };\n        let position = cache.position(&position_id).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"fill {} maps to position {position_id}, which is not cached\",\n                report.trade_id,\n            )\n        })?;\n\n        anyhow::ensure!(\n            position.account_id == report.account_id\n                && position.instrument_id == report.instrument_id,\n            \"fill {} maps to position {position_id} with a different account or instrument\",\n            report.trade_id,\n        );\n        anyhow::ensure!(\n            position.is_open(),\n            \"fill {} maps to non-open position {position_id}\",\n            report.trade_id,\n        );\n        anyhow::ensure!(\n            !position.is_opposite_side(report.order_side) || report.last_qty <= position.quantity,\n            \"fill {} without a venue position ID would cross position {position_id}\",\n            report.trade_id,\n        );\n\n        report.venue_position_id = Some(position_id);\n        Ok(PositionFillReportPreparation::Ready)","sourceCodeStart":2874,"sourceCodeEnd":2910,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/execution/manager.rs#L2874-L2910","documentation":"The cached position resolved for this fill has an account_id or instrument_id that differs from the fill report's. A fill can only be applied to a position on the same account and instrument, so the manager rejects the report as misattributed.","triggerScenarios":"cache.position(position_id) returns a position whose account_id != report.account_id or instrument_id != report.instrument_id. Caused by position ID collisions in a custom adapter's mapping, wrong instrument symbology, or multi-account routing errors.","commonSituations":"Adapters that generate position IDs without instrument/account scoping so IDs collide across instruments; an instrument mapping change mid-session; fills from a sub-account routed to a parent-account position.","solutions":["Scope adapter-generated position IDs by instrument (and account) so they cannot collide","Fix instrument symbology mapping so the same venue position resolves to one nautilus instrument","Verify account_id derivation in the adapter matches the account that owns the position","Clear corrupt cache mappings and re-reconcile with venue position state"],"exampleFix":"// before (global counter)\nlet position_id = VenuePositionId::new(format!(\"{n}\"));\n// after (scoped)\nlet position_id = VenuePositionId::new(format!(\"{instrument}-{account}-{n}\"));","handlingStrategy":"validation","validationCode":"if let Some(pos) = cache.position(&position_id) {\n    assert_eq!(pos.account_id, report.account_id);\n    assert_eq!(pos.instrument_id, report.instrument_id);\n}","typeGuard":"fn position_matches_report(pos: &Position, report: &TradeReport) -> bool {\n    pos.account_id == report.account_id && pos.instrument_id == report.instrument_id\n}","tryCatchPattern":null,"preventionTips":["Scope generated position IDs by instrument and account","Keep one authoritative instrument symbology mapping","Verify account routing for multi-account deployments"],"tags":["rust","live-execution","position-mapping","account-mismatch"],"backgroundTag":"internal-invariant-violation","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"}