Skip to content

Add total P&L support for single account view#45

Open
dbigham wants to merge 11 commits into
mainfrom
codex/implement-total-pl-for-single-account
Open

Add total P&L support for single account view#45
dbigham wants to merge 11 commits into
mainfrom
codex/implement-total-pl-for-single-account

Conversation

@dbigham

@dbigham dbigham commented Oct 3, 2025

Copy link
Copy Markdown
Owner

Summary

  • collect net deposit history from account activities and cache the results per login/account
  • derive total P&L per currency from account balances and attach the values to balance summaries when a single account is selected
  • surface the computed total P&L in the API response so the main card can display it for single-account views

Testing

  • node --check server/src/index.js

https://chatgpt.com/codex/tasks/task_e_68dfba66908c832da9e32109d1dcc46f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment thread server/src/index.js Outdated
Comment on lines +1163 to +1177
if (balanceSummary.combined) {
const rates = buildCurrencyRateMapFromSummary(balanceSummary, baseCurrency);
Object.entries(balanceSummary.combined).forEach(([key, entry]) => {
const normalized = normalizeCurrencyCode(key);
if (!normalized) {
return;
}
const equity = entry && entry.totalEquity;
if (!isFiniteNumber(equity)) {
return;
}
let convertedDeposits = 0;
totalsMap.forEach((amount, sourceCurrency) => {
convertedDeposits += convertAmountToCurrency(amount, sourceCurrency, normalized, rates, baseCurrency);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ignore deposits in currencies no longer present in balance summary

When computing total P&L the code builds a rate map only from currencies that appear in the current balance summary and then converts every historical deposit using those rates. If a user previously deposited funds in a currency they no longer hold (so that currency is absent from the balance summary), convertAmountToCurrency receives no rate for that currency and returns 0, effectively dropping those deposits from convertedDeposits. The resulting combined totalPnl will be overstated because past deposits in missing currencies are never subtracted. Consider an account that once deposited USD, converted everything to CAD, and now only holds CAD: total P&L will ignore the USD contributions entirely. The conversion should fall back to a reasonable rate (e.g., derived from the activity currency or base currency) instead of skipping the amount when the currency is absent from the current balances.

Useful? React with 👍 / 👎.

@dbigham
dbigham force-pushed the codex/implement-total-pl-for-single-account branch from 9ea89d3 to c3b5f5f Compare October 4, 2025 12:06
@dbigham
dbigham force-pushed the main branch 3 times, most recently from c7f2145 to c8636e3 Compare November 15, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant