fix: count brokerage cash once in portfolio totals (WealthLedger/backend#140) #141

Merged
codex-bot merged 2 commits from fix/140-portfolio-cash-double-count into develop 2026-10-28 08:46:38 +03:00
Owner

Closes #140

Changes

  • totalsByCurrency and portfolioStructure skip CURRENCY positions: T-Bank returns the same cash both as getPositions().money and as RUB000UTSTOM/USD800UTSTOM positions. Same rule as in brokerage-accounts.service.ts.
  • unrealizedReturnByCurrency.percent is null for a currency with a short position (negative cost basis flipped the sign / netted with longs), consistent with instrument-position.ts.
  • Migration 20261028080000_reset_inflated_portfolio_value_points deletes all TbankPortfolioValuePoint rows written by the old code. They cannot be recomputed exactly (no historical compositions or FX rates); points have no public read path. TbankPortfolioValueHistory is kept. Owner-approved destructive data change; back up the SQLite file before deploy.

Verification

  • New regression tests fail without the fix (3) and pass with it; fixture mirrors dev.db account 2197225275 (121.49 instead of 122.74).
  • npm run verify green (293/293 unit, lint, typecheck, build).
  • test:sqlite tbank-value-history.e2e-spec.ts 13/13.
  • Migration applied on a copy of dev.db with a seeded point: points 1 → 0, history row kept, migrate status up to date.

Follow-up

Closes #140 ## Changes - `totalsByCurrency` and `portfolioStructure` skip `CURRENCY` positions: T-Bank returns the same cash both as `getPositions().money` and as `RUB000UTSTOM`/`USD800UTSTOM` positions. Same rule as in `brokerage-accounts.service.ts`. - `unrealizedReturnByCurrency.percent` is `null` for a currency with a short position (negative cost basis flipped the sign / netted with longs), consistent with `instrument-position.ts`. - Migration `20261028080000_reset_inflated_portfolio_value_points` deletes all `TbankPortfolioValuePoint` rows written by the old code. They cannot be recomputed exactly (no historical compositions or FX rates); points have no public read path. `TbankPortfolioValueHistory` is kept. **Owner-approved destructive data change; back up the SQLite file before deploy.** ## Verification - New regression tests fail without the fix (3) and pass with it; fixture mirrors dev.db account 2197225275 (121.49 instead of 122.74). - `npm run verify` green (293/293 unit, lint, typecheck, build). - `test:sqlite tbank-value-history.e2e-spec.ts` 13/13. - Migration applied on a copy of dev.db with a seeded point: points 1 → 0, history row kept, `migrate status` up to date. ## Follow-up - WealthLedger/specs#60: `portfolio-view` wording should state that CURRENCY positions mirror cash (related WealthLedger/frontend#59).
codex-bot added 2 commits 2026-10-28 08:00:32 +03:00
fix: reset portfolio value points inflated by double-counted cash (WealthLedger/backend#140)
Backend verify / commits (pull_request) Successful in 27s
Backend verify / security (pull_request) Skipped
Backend verify / verify (pull_request) Skipped
Backend verify / commits (push) Skipped
Backend verify / security (push) Successful in 9s
Backend verify / verify (push) Failing after 4m33s
2325b63883
codex-bot merged commit 2325b63883 into develop 2026-10-28 08:46:38 +03:00
codex-bot deleted branch fix/140-portfolio-cash-double-count 2026-10-28 08:46:38 +03:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: WealthLedger/backend#141