feat(tbank): add brokerage account summaries

This commit is contained in:
2026-08-26 20:57:55 +03:00
parent 84fabd264f
commit e489d45f88
7 changed files with 240 additions and 19 deletions
+2 -13
View File
@@ -8,6 +8,7 @@ import {
multiply,
subtract,
} from './decimal';
import { totalsByCurrency } from './portfolio-totals';
import { MoneyDto, PortfolioDto, PortfolioPositionDto } from './portfolio.dto';
import { TbankAccessService } from './tbank-access.service';
import { InstrumentMetadataService } from './instrument-metadata.service';
@@ -106,22 +107,10 @@ export class PortfolioService {
currency,
value: formatDecimal(value),
}));
const totals = new Map(cash);
for (const position of positions) {
if (!position?.currentValue) continue;
const amount = decimalFromString(position.currentValue.value);
totals.set(
position.currentValue.currency,
add(totals.get(position.currentValue.currency) ?? decimal({}), amount),
);
}
return {
lastSuccessfulAt: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
isStale: false,
totalsByCurrency: [...totals].map(([currency, value]) => ({
currency,
value: formatDecimal(value),
})),
totalsByCurrency: totalsByCurrency(upstream, money),
positions: positions.filter(
(position): position is PortfolioPositionDto => position !== null,
),