feat(tbank): add brokerage account summaries
This commit is contained in:
@@ -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,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user