feat(research): add owner-aware ledger and intraday storage

Implement reviewed F02/D02: exact owner accounting, atomic funding checks, idempotent receipts and ledger checkpoints; connect existing EOD intraday storage through validated research admission without active financial-engine cutover.
This commit is contained in:
Boki 2026-10-22 21:16:53 -04:00
parent b4af840d4e
commit b65acccd91
15 changed files with 2704 additions and 104 deletions

View file

@ -15,6 +15,16 @@ Scheduling source of truth: [manifest entry F02](../manifest.json). No task is a
Implement one owner-keyed ledger from its first version; absorb F03 rather than building aggregate cost basis and replacing it later. Adapt existing Rust position calculations. Store owned quantity and remaining cost amount; derive average price and account aggregates. For a partial disposal, round the proportional released basis at posting precision; final disposal releases the exact residual. Fees are separate postings. Use one internal apply(state,command) kernel for resident research and staged durable transactions.
### Seventh-wave implementation boundary
F01 is committed in `b4af840`. Keep this ledger additive: no replacement of active legacy position/accounting code, native binding, SQL transaction integration or paper migration. ADR-005 remains unapproved; F02 provides the in-memory transition/checkpoint seam, not its durable adapter.
- A ledger checkpoint is distinct from F01's economic projection. It retains genesis, books including closed-position realized P&L, cash/fees, marks, risk-session identity, revision and ordered accepted receipts/aliases. Restore verifies by replay and canonical state comparison. It is not an order/replay/strategy/RNG session snapshot.
- Exact multiplication and proportional release use maintained arithmetic with a single final half-away posting boundary, not precision-losing decimal intermediates. Account valuation sums owner-level marked postings; missing marks reject valuation instead of inventing zero or cost-based prices.
- Invalid commands fail atomically without changing balances, books, marks or receipts. Basic cash funding includes fees. Reservation and portfolio risk policies remain F04, including recording accepted risk-rejection outcomes.
- Identical command retry returns its original receipt even after later transitions. Identical fill under a new command ID aliases that receipt, explicitly marked replayed: compare event time and the entire canonical fill body, excluding only command ID. Different fill content or reuse of a fee ID by another fill rejects. Never emit duplicate economic deltas.
- Normal transitions stage only affected state; checkpoint serialization/replay is explicit. Record repeatable scoped transition and checkpoint/restore measurements without claiming end-to-end research throughput.
## Exclusions
No unrelated refactor, new service, broker enablement, or silent reinterpretation of historical results.