Compare commits
29 Commits
feature/br
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 353face40e | |||
| a6a46e0d84 | |||
| a6250f1592 | |||
| 22e9656e92 | |||
| 19a924647e | |||
| 8202d292cd | |||
| 2e1fc5976a | |||
| 52221dfdc1 | |||
| 7d2ccf9301 | |||
| 62ac3c387d | |||
| 58a4663aaf | |||
| c2e515ba8d | |||
| 71a18e8656 | |||
| be1c2cc701 | |||
| b94340823b | |||
| c69e55e045 | |||
| 94506e38c2 | |||
| 19d3c36c9e | |||
| 491a51cfb8 | |||
| 5adbcbd7bd | |||
| c82b26acf9 | |||
| ba2ed6a049 | |||
| 4d9663a906 | |||
| e0723b3ab6 | |||
| 29ba82f4bf | |||
| 5d478ff06c | |||
| e7233d85ee | |||
| b38346dd19 | |||
| 1e25a0152a |
79
CHANGELOG.md
79
CHANGELOG.md
@@ -1,5 +1,84 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [Backend 0.15.6] - 2026-08-29
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Count broker withdrawals from explicit positive transfers to family accounts, linked by the broker account number in the operation description.
|
||||||
|
|
||||||
|
## [Backend 0.15.5] - 2026-08-28
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Trust a matched family-account transfer even when the broker uses an unexpected operation description.
|
||||||
|
|
||||||
|
## [Backend 0.15.4] - 2026-08-28
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Reconcile split broker withdrawals with one aggregated transfer to a family account.
|
||||||
|
|
||||||
|
## [Backend 0.15.3] - 2026-08-28
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Recognize confirmed broker withdrawals even when the broker description does not contain the word «вывод».
|
||||||
|
|
||||||
|
## [Backend 0.15.2] - 2026-08-28
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Count broker deposits and withdrawals only when matched to a transfer on another family account, while retaining real explicit top-ups and withdrawals.
|
||||||
|
|
||||||
|
## [Backend 0.15.1] - 2026-08-28
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Excluded internal transfers for pending securities purchases from broker contributions.
|
||||||
|
|
||||||
|
## [Frontend 0.16.0 / Backend 0.15.0 / Shared 0.10.0] - 2026-08-28
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Revalued open portfolio positions from current MOEX quotes with a fallback to the latest broker report.
|
||||||
|
- Broadened broker withdrawal detection in investment performance.
|
||||||
|
|
||||||
|
## [Frontend 0.15.2] - 2026-08-27
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Clarified that the broker income metric includes coupons, dividends, and interest.
|
||||||
|
|
||||||
|
## [Frontend 0.15.1] - 2026-08-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a frontend API contract check for portfolio overview, history, and performance requests.
|
||||||
|
|
||||||
|
## [Backend 0.14.1] - 2026-08-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added SQL coverage for repeated and overlapping broker portfolio report imports.
|
||||||
|
|
||||||
|
## [Frontend 0.15.0 / Backend 0.14.0 / Shared 0.9.0] - 2026-08-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added separate broker investment performance metrics: contributions, withdrawals, income, fees, realized and unrealized results.
|
||||||
|
|
||||||
|
## [Frontend 0.14.0 / Backend 0.13.0 / Shared 0.8.0] - 2026-08-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added portfolio valuation history by imported broker report dates.
|
||||||
|
|
||||||
|
## [Frontend 0.13.0 / Backend 0.12.0 / Shared 0.7.0] - 2026-08-27
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a separate portfolio view with the latest broker and IIS positions and total valuation.
|
||||||
|
|
||||||
## [Frontend 0.12.0 / Backend 0.11.0 / Shared 0.6.0] - 2026-08-26
|
## [Frontend 0.12.0 / Backend 0.11.0 / Shared 0.6.0] - 2026-08-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@family-budget/backend",
|
"name": "@family-budget/backend",
|
||||||
"version": "0.11.0",
|
"version": "0.15.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsx watch src/app.ts",
|
"dev": "tsx watch src/app.ts",
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
"test:analytics": "tsx src/services/analyticsSemantics.test.ts",
|
"test:analytics": "tsx src/services/analyticsSemantics.test.ts",
|
||||||
"test:analytics:query": "tsx src/routes/analytics.test.ts",
|
"test:analytics:query": "tsx src/routes/analytics.test.ts",
|
||||||
"test:portfolio": "tsx src/services/portfolio.test.ts",
|
"test:portfolio": "tsx src/services/portfolio.test.ts",
|
||||||
|
"test:portfolio:overview": "tsx src/services/portfolioOverview.test.ts",
|
||||||
|
"test:portfolio:performance": "tsx src/services/portfolioOverview.test.ts",
|
||||||
|
"test:portfolio:moex": "tsx src/services/moex.test.ts",
|
||||||
"test:portfolio:db": "NODE_ENV=test tsx src/services/portfolio.integration.test.ts",
|
"test:portfolio:db": "NODE_ENV=test tsx src/services/portfolio.integration.test.ts",
|
||||||
"test:transactions": "tsx src/services/transactions.test.ts",
|
"test:transactions": "tsx src/services/transactions.test.ts",
|
||||||
"test:analytics:db": "NODE_ENV=test tsx src/services/analytics.integration.test.ts",
|
"test:analytics:db": "NODE_ENV=test tsx src/services/analytics.integration.test.ts",
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ import categoriesRouter from './routes/categories';
|
|||||||
import categoryRulesRouter from './routes/categoryRules';
|
import categoryRulesRouter from './routes/categoryRules';
|
||||||
import analyticsRouter from './routes/analytics';
|
import analyticsRouter from './routes/analytics';
|
||||||
import portfolioRouter from './routes/portfolio';
|
import portfolioRouter from './routes/portfolio';
|
||||||
|
import portfolioOverviewRouter from './routes/portfolioOverview';
|
||||||
|
import portfolioHistoryRouter from './routes/portfolioHistory';
|
||||||
|
import portfolioPerformanceRouter from './routes/portfolioPerformance';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.set('trust proxy', 1);
|
app.set('trust proxy', 1);
|
||||||
@@ -45,6 +48,9 @@ app.use('/api/categories', categoriesRouter);
|
|||||||
app.use('/api/category-rules', categoryRulesRouter);
|
app.use('/api/category-rules', categoryRulesRouter);
|
||||||
app.use('/api/analytics', analyticsRouter);
|
app.use('/api/analytics', analyticsRouter);
|
||||||
app.use('/api/import/portfolio', portfolioRouter);
|
app.use('/api/import/portfolio', portfolioRouter);
|
||||||
|
app.use('/api/portfolio', portfolioOverviewRouter);
|
||||||
|
app.use('/api/portfolio/history', portfolioHistoryRouter);
|
||||||
|
app.use('/api/portfolio/performance', portfolioPerformanceRouter);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
(
|
(
|
||||||
|
|||||||
14
backend/src/routes/portfolioHistory.ts
Normal file
14
backend/src/routes/portfolioHistory.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { asyncHandler } from '../utils';
|
||||||
|
import { getPortfolioHistory } from '../services/portfolio';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/',
|
||||||
|
asyncHandler(async (_req, res) => {
|
||||||
|
res.json(await getPortfolioHistory());
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
||||||
14
backend/src/routes/portfolioOverview.ts
Normal file
14
backend/src/routes/portfolioOverview.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { asyncHandler } from '../utils';
|
||||||
|
import { getPortfolioOverview } from '../services/portfolio';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get(
|
||||||
|
'/',
|
||||||
|
asyncHandler(async (_req, res) => {
|
||||||
|
res.json(await getPortfolioOverview());
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
export default router;
|
||||||
9
backend/src/routes/portfolioPerformance.ts
Normal file
9
backend/src/routes/portfolioPerformance.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import { asyncHandler } from '../utils';
|
||||||
|
import { getPortfolioPerformance } from '../services/portfolio';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
router.get('/', asyncHandler(async (_req, res) => {
|
||||||
|
res.json(await getPortfolioPerformance());
|
||||||
|
}));
|
||||||
|
export default router;
|
||||||
23
backend/src/services/moex.test.ts
Normal file
23
backend/src/services/moex.test.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { getMoexQuote } from './moex';
|
||||||
|
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
globalThis.fetch = (async (input: string | URL | Request) => {
|
||||||
|
const url = String(input);
|
||||||
|
if (url.includes('/securities/RU0000000002.json')) return new Response('{}', { status: 404 });
|
||||||
|
if (url.includes('/securities.json') && url.includes('RU0000000002')) return new Response(JSON.stringify({ securities: { columns: ['secid', 'isin'], data: [['TEST2', 'RU0000000002']] } }), { status: 200 });
|
||||||
|
if (url.includes('/securities/TEST2.json') && url.includes('iss.only=boards')) return new Response(JSON.stringify({ boards: { columns: ['engine', 'market', 'boardid', 'secid'], data: [['stock', 'shares', 'TQBR', 'TEST2']] } }), { status: 200 });
|
||||||
|
if (url.includes('/securities/RU0000000001.json')) return new Response(JSON.stringify({ boards: { columns: ['engine', 'market', 'boardid', 'secid'], data: [['stock', 'shares', 'TQBR', 'TEST']] } }), { status: 200 });
|
||||||
|
return new Response(JSON.stringify({ marketdata: { columns: ['LAST', 'LCURRENTPRICE', 'WAPRICE', 'UPDATETIME'], data: [[123.45, null, null, '2026-08-28 12:00:00']] } }), { status: 200 });
|
||||||
|
}) as typeof fetch;
|
||||||
|
|
||||||
|
async function run(): Promise<void> {
|
||||||
|
const quote = await getMoexQuote('RU0000000001');
|
||||||
|
assert.deepEqual(quote, { price: 123.45, at: '2026-08-28 12:00:00' });
|
||||||
|
assert.deepEqual(await getMoexQuote('RU0000000002'), { price: 123.45, at: '2026-08-28 12:00:00' });
|
||||||
|
assert.equal(await getMoexQuote('bad-isin'), null);
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
console.log('MOEX quote: OK');
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
54
backend/src/services/moex.ts
Normal file
54
backend/src/services/moex.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
type IssBlock = { columns?: string[]; data?: unknown[][] };
|
||||||
|
|
||||||
|
export type MarketQuote = { price: number; at: string | null };
|
||||||
|
|
||||||
|
const BASE_URL = 'https://iss.moex.com/iss';
|
||||||
|
const timeoutMs = 5000;
|
||||||
|
|
||||||
|
function rows(block: IssBlock | undefined): Record<string, unknown>[] {
|
||||||
|
if (!block?.columns || !block.data) return [];
|
||||||
|
return block.data.map((row) => Object.fromEntries(block.columns!.map((column, index) => [column.toLowerCase(), row[index]])));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getJson(url: string): Promise<Record<string, IssBlock>> {
|
||||||
|
const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs), headers: { accept: 'application/json' } });
|
||||||
|
if (!response.ok) throw new Error(`MOEX HTTP ${response.status}`);
|
||||||
|
return await response.json() as Record<string, IssBlock>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function numberValue(value: unknown): number | null {
|
||||||
|
const number = typeof value === 'number' ? value : Number(value);
|
||||||
|
return Number.isFinite(number) && number > 0 ? number : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMoexQuote(isin: string): Promise<MarketQuote | null> {
|
||||||
|
if (!/^RU[A-Z0-9]{10}$/.test(isin)) return null;
|
||||||
|
try {
|
||||||
|
let info: Record<string, IssBlock> = {};
|
||||||
|
try {
|
||||||
|
info = await getJson(`${BASE_URL}/securities/${encodeURIComponent(isin)}.json?iss.meta=off&iss.only=boards&boards.columns=engine,market,boardid,secid`);
|
||||||
|
} catch { /* search by ISIN below */ }
|
||||||
|
let boards = rows(info.boards);
|
||||||
|
if (boards.length === 0) {
|
||||||
|
const search = await getJson(`${BASE_URL}/securities.json?q=${encodeURIComponent(isin)}&iss.meta=off&iss.only=securities&securities.columns=secid,isin`);
|
||||||
|
const match = rows(search.securities).find((item) => String(item.isin ?? '').toUpperCase() === isin);
|
||||||
|
if (typeof match?.secid === 'string') {
|
||||||
|
info = await getJson(`${BASE_URL}/securities/${encodeURIComponent(match.secid)}.json?iss.meta=off&iss.only=boards&boards.columns=engine,market,boardid,secid`);
|
||||||
|
boards = rows(info.boards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boards = boards.filter((item) => typeof item.engine === 'string' && typeof item.market === 'string' && typeof item.boardid === 'string' && typeof item.secid === 'string');
|
||||||
|
for (const board of boards) {
|
||||||
|
try {
|
||||||
|
const quote = await getJson(`${BASE_URL}/engines/${board.engine}/markets/${board.market}/boards/${board.boardid}/securities/${encodeURIComponent(String(board.secid))}.json?iss.meta=off&iss.only=marketdata&marketdata.columns=LAST,LCURRENTPRICE,WAPRICE,UPDATETIME`);
|
||||||
|
const market = rows(quote.marketdata)[0];
|
||||||
|
if (!market) continue;
|
||||||
|
const price = numberValue(market.last) ?? numberValue(market.lcurrentprice) ?? numberValue(market.waprice);
|
||||||
|
if (price !== null) return { price, at: typeof market.updatetime === 'string' ? market.updatetime : null };
|
||||||
|
} catch { /* try the next trading board */ }
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,12 @@ const payload = {
|
|||||||
positions: [{ instrument: 'Test Bond', isin: 'RU0000000001', quantity: '1.000', price: '100.123456', valuation: '100.123456' }],
|
positions: [{ instrument: 'Test Bond', isin: 'RU0000000001', quantity: '1.000', price: '100.123456', valuation: '100.123456' }],
|
||||||
trades: [{ instrument: 'Test Bond', isin: 'RU0000000001', concludedAt: '2026-08-10T10:00:00+03:00', side: 'Покупка', quantity: '1.000', settlementAmount: '100.123456' }],
|
trades: [{ instrument: 'Test Bond', isin: 'RU0000000001', concludedAt: '2026-08-10T10:00:00+03:00', side: 'Покупка', quantity: '1.000', settlementAmount: '100.123456' }],
|
||||||
};
|
};
|
||||||
|
const overlappingPayload = {
|
||||||
|
...payload,
|
||||||
|
reportPeriod: { from: '2026-08-10', to: '2026-08-25' },
|
||||||
|
positions: [{ ...payload.positions[0], valuation: '120.000000' }],
|
||||||
|
trades: [{ ...payload.trades[0], sourceId: 'second-trade', concludedAt: '2026-08-15T10:00:00+03:00', side: 'Продажа', quantity: '0.500', settlementAmount: '60.000000' }],
|
||||||
|
};
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -17,6 +23,12 @@ async function run(): Promise<void> {
|
|||||||
assert.equal(second.duplicateTrades, 1);
|
assert.equal(second.duplicateTrades, 1);
|
||||||
const rows = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
const rows = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
||||||
assert.equal(rows.rows[0].count, 1);
|
assert.equal(rows.rows[0].count, 1);
|
||||||
|
const overlapping = await importPortfolio(overlappingPayload);
|
||||||
|
assert.equal(overlapping.importedTrades, 1);
|
||||||
|
const reports = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_reports WHERE account_id = $1', [first.accountId]);
|
||||||
|
assert.equal(reports.rows[0].count, 2);
|
||||||
|
const trades = await pool.query('SELECT COUNT(*)::int AS count FROM portfolio_trades WHERE account_id = $1', [first.accountId]);
|
||||||
|
assert.equal(trades.rows[0].count, 2);
|
||||||
console.log('portfolio import SQL: OK');
|
console.log('portfolio import SQL: OK');
|
||||||
} finally {
|
} finally {
|
||||||
await pool.query("DELETE FROM portfolio_trades WHERE account_id IN (SELECT id FROM accounts WHERE bank = 'PORTFOLIO_TEST' AND account_number = 'portfolio-test')");
|
await pool.query("DELETE FROM portfolio_trades WHERE account_id IN (SELECT id FROM accounts WHERE bank = 'PORTFOLIO_TEST' AND account_number = 'portfolio-test')");
|
||||||
|
|||||||
@@ -1,10 +1,84 @@
|
|||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import type { PoolClient } from 'pg';
|
import type { PoolClient } from 'pg';
|
||||||
import { pool } from '../db/pool';
|
import { pool } from '../db/pool';
|
||||||
import type { ImportPortfolioResponse, PortfolioFile, PortfolioTrade } from '@family-budget/shared';
|
import { maskAccountNumber } from '../utils';
|
||||||
|
import { getMoexQuote } from './moex';
|
||||||
|
import type { ImportPortfolioResponse, PortfolioFile, PortfolioHistoryResponse, PortfolioOverviewResponse, PortfolioPerformanceResponse, PortfolioTrade } from '@family-budget/shared';
|
||||||
|
|
||||||
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||||
|
|
||||||
|
type PortfolioOverviewRow = {
|
||||||
|
account_id: number | string;
|
||||||
|
alias: string | null;
|
||||||
|
bank: string;
|
||||||
|
account_number: string;
|
||||||
|
report_period_to: string;
|
||||||
|
total_valuation: string | number | null;
|
||||||
|
instrument: string | null;
|
||||||
|
isin: string | null;
|
||||||
|
quantity: string | number | null;
|
||||||
|
price: string | number | null;
|
||||||
|
valuation: string | number | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
type PortfolioHistoryRow = {
|
||||||
|
account_id: number | string;
|
||||||
|
alias: string | null;
|
||||||
|
bank: string;
|
||||||
|
account_number: string;
|
||||||
|
report_period_to: string;
|
||||||
|
total_valuation: string | number | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PerformanceCashRow = { id: number | string; account_id: number | string; alias: string | null; bank: string; account_number: string; account_type: string | null; operation_at: string; amount_signed: number | string; description: string };
|
||||||
|
type PerformanceTradeRow = { account_id: number | string; side: string; quantity: string | number; settlement_amount: string | number | null; settlement_commission: string | number | null; trade_commission: string | number | null; isin: string | null; instrument: string };
|
||||||
|
type PerformancePositionRow = { account_id: number | string; quantity: string | number; valuation: string | number | null; isin: string | null; instrument: string };
|
||||||
|
|
||||||
|
export type PortfolioCashKind = 'income' | 'contribution' | 'withdrawal' | 'other';
|
||||||
|
|
||||||
|
export function extractBrokerWithdrawalAccount(description: string): string | null {
|
||||||
|
return description.toLowerCase().replace(/ё/g, 'е').match(/вывод денежных средств с брокерского счета\s+([0-9]+)/)?.[1] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function classifyPortfolioCash(amount: number, description: string, matchedExternalTransfer = false): PortfolioCashKind {
|
||||||
|
const text = description.toLowerCase().replace(/ё/g, 'е');
|
||||||
|
if (amount > 0 && /дивиденд|купон|процент/.test(text)) return 'income';
|
||||||
|
if (amount > 0 && (matchedExternalTransfer || /пополнение/.test(text)) && !text.includes('под нерассчитанные сделки')) return 'contribution';
|
||||||
|
if (amount < 0 && matchedExternalTransfer) return 'withdrawal';
|
||||||
|
if (amount < 0 && /вывод|перевод денежных средств|перечисление денежных средств|возврат денежных средств/.test(text) && !text.includes('под нерассчитанные сделки')) return 'withdrawal';
|
||||||
|
return 'other';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sumKnownPortfolioValuations(values: Array<number | null>): number | null {
|
||||||
|
const known = values.filter((value): value is number => value !== null && Number.isFinite(value));
|
||||||
|
return known.length > 0 ? known.reduce((sum, value) => sum + value, 0) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function matchExternalCashTransfers(rows: PerformanceCashRow[]): Set<number | string> {
|
||||||
|
const broker = rows.filter((row) => ['brokerage', 'iis'].includes(row.account_type ?? ''));
|
||||||
|
const external = rows.filter((row) => !['brokerage', 'iis'].includes(row.account_type ?? ''));
|
||||||
|
const matchedBroker = new Set<number | string>();
|
||||||
|
const matchedExternal = new Set<number | string>();
|
||||||
|
for (const target of external) {
|
||||||
|
const targetAmount = Math.round(Number(target.amount_signed));
|
||||||
|
if (!targetAmount || matchedExternal.has(target.id)) continue;
|
||||||
|
const candidates = broker.filter((row) => !matchedBroker.has(row.id) && Math.sign(Number(row.amount_signed)) === -Math.sign(targetAmount) && Math.abs(Math.round(Number(row.amount_signed))) <= Math.abs(targetAmount) && Math.abs(Date.parse(row.operation_at) - Date.parse(target.operation_at)) <= 3 * 24 * 60 * 60 * 1000);
|
||||||
|
const exact = candidates.find((row) => Math.round(Number(row.amount_signed)) === -targetAmount);
|
||||||
|
let group: PerformanceCashRow[] = exact ? [exact] : [];
|
||||||
|
if (group.length === 0) {
|
||||||
|
for (let index = 0; index < candidates.length && group.length === 0; index += 1) {
|
||||||
|
for (const second of candidates.slice(index + 1)) {
|
||||||
|
if (Math.round(Number(candidates[index].amount_signed)) + Math.round(Number(second.amount_signed)) === -targetAmount) { group = [candidates[index], second]; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (group.length === 0) continue;
|
||||||
|
matchedExternal.add(target.id);
|
||||||
|
group.forEach((row) => matchedBroker.add(row.id));
|
||||||
|
}
|
||||||
|
return matchedBroker;
|
||||||
|
}
|
||||||
|
|
||||||
function decimalValue(value: unknown, field: string, required = false): string | null {
|
function decimalValue(value: unknown, field: string, required = false): string | null {
|
||||||
if (value == null || value === '') {
|
if (value == null || value === '') {
|
||||||
if (required) throw new Error(`${field} is required`);
|
if (required) throw new Error(`${field} is required`);
|
||||||
@@ -103,3 +177,223 @@ export async function importPortfolio(body: unknown, db: Pick<typeof pool, 'conn
|
|||||||
if (ownsTransaction) client.release();
|
if (ownsTransaction) client.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toPortfolioOverview(rows: PortfolioOverviewRow[]): PortfolioOverviewResponse {
|
||||||
|
const accounts = new Map<number, PortfolioOverviewResponse['accounts'][number]>();
|
||||||
|
for (const row of rows) {
|
||||||
|
const accountId = Number(row.account_id);
|
||||||
|
let account = accounts.get(accountId);
|
||||||
|
if (!account) {
|
||||||
|
account = {
|
||||||
|
accountId,
|
||||||
|
accountName: row.alias || `${row.bank} · ${maskAccountNumber(row.account_number)}`,
|
||||||
|
reportPeriodTo: row.report_period_to,
|
||||||
|
totalValuation: row.total_valuation === null ? null : String(row.total_valuation),
|
||||||
|
positions: [],
|
||||||
|
};
|
||||||
|
accounts.set(accountId, account);
|
||||||
|
}
|
||||||
|
if (row.instrument !== null) {
|
||||||
|
const valuation = row.valuation === null ? null : String(row.valuation);
|
||||||
|
account.positions.push({
|
||||||
|
instrument: row.instrument,
|
||||||
|
isin: row.isin,
|
||||||
|
quantity: String(row.quantity),
|
||||||
|
price: row.price === null ? null : String(row.price),
|
||||||
|
valuation,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { accounts: [...accounts.values()] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPortfolioOverview(): Promise<PortfolioOverviewResponse> {
|
||||||
|
const { rows } = await pool.query<PortfolioOverviewRow>(
|
||||||
|
`SELECT a.id AS account_id, a.alias, a.bank, a.account_number,
|
||||||
|
r.report_period_to,
|
||||||
|
SUM(p.valuation) OVER (PARTITION BY a.id) AS total_valuation,
|
||||||
|
p.instrument, p.isin, p.quantity, p.price, p.valuation
|
||||||
|
FROM accounts a
|
||||||
|
JOIN LATERAL (
|
||||||
|
SELECT id, report_period_to, reported_at, imported_at
|
||||||
|
FROM portfolio_reports
|
||||||
|
WHERE account_id = a.id
|
||||||
|
ORDER BY report_period_to DESC, imported_at DESC, id DESC
|
||||||
|
LIMIT 1
|
||||||
|
) r ON TRUE
|
||||||
|
LEFT JOIN portfolio_positions p ON p.report_id = r.id
|
||||||
|
WHERE a.account_type IN ('brokerage', 'iis')
|
||||||
|
ORDER BY a.id, p.valuation DESC NULLS LAST, p.id`,
|
||||||
|
);
|
||||||
|
const overview = toPortfolioOverview(rows);
|
||||||
|
const quoteCache = new Map<string, Awaited<ReturnType<typeof getMoexQuote>>>();
|
||||||
|
for (const account of overview.accounts) {
|
||||||
|
const currentValuations: Array<number | null> = [];
|
||||||
|
let hasMarket = false;
|
||||||
|
let hasFallback = false;
|
||||||
|
let valuationAsOf: string | null = null;
|
||||||
|
for (const position of account.positions) {
|
||||||
|
if (!position.isin) { hasFallback = true; currentValuations.push(position.valuation === null ? null : Number(position.valuation)); continue; }
|
||||||
|
if (!quoteCache.has(position.isin)) quoteCache.set(position.isin, await getMoexQuote(position.isin));
|
||||||
|
const quote = quoteCache.get(position.isin);
|
||||||
|
if (!quote) { hasFallback = true; currentValuations.push(position.valuation === null ? null : Number(position.valuation)); continue; }
|
||||||
|
const reportPrice = position.price === null ? null : Number(position.price);
|
||||||
|
const reportValuation = position.valuation === null ? null : Number(position.valuation);
|
||||||
|
const currentValuationForPosition = reportPrice && reportValuation !== null
|
||||||
|
? reportValuation * quote.price / reportPrice
|
||||||
|
: Number(position.quantity) * quote.price;
|
||||||
|
if (!Number.isFinite(currentValuationForPosition)) continue;
|
||||||
|
position.currentPrice = String(quote.price);
|
||||||
|
position.currentValuation = String(currentValuationForPosition);
|
||||||
|
position.quoteAt = quote.at;
|
||||||
|
hasMarket = true;
|
||||||
|
currentValuations.push(currentValuationForPosition);
|
||||||
|
if (quote.at && (!valuationAsOf || quote.at > valuationAsOf)) valuationAsOf = quote.at;
|
||||||
|
}
|
||||||
|
const currentValuation = sumKnownPortfolioValuations(currentValuations);
|
||||||
|
if (currentValuation !== null) {
|
||||||
|
account.currentValuation = String(currentValuation);
|
||||||
|
account.valuationAsOf = valuationAsOf;
|
||||||
|
account.valuationSource = hasMarket ? (hasFallback ? 'mixed' : 'market') : 'report';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return overview;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toPortfolioHistory(rows: PortfolioHistoryRow[]): PortfolioHistoryResponse {
|
||||||
|
const accounts = new Map<number, PortfolioHistoryResponse['accounts'][number]>();
|
||||||
|
for (const row of rows) {
|
||||||
|
const accountId = Number(row.account_id);
|
||||||
|
let account = accounts.get(accountId);
|
||||||
|
if (!account) {
|
||||||
|
account = {
|
||||||
|
accountId,
|
||||||
|
accountName: row.alias || `${row.bank} · ${maskAccountNumber(row.account_number)}`,
|
||||||
|
points: [],
|
||||||
|
};
|
||||||
|
accounts.set(accountId, account);
|
||||||
|
}
|
||||||
|
account.points.push({
|
||||||
|
reportPeriodTo: row.report_period_to,
|
||||||
|
totalValuation: row.total_valuation === null ? null : String(row.total_valuation),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { accounts: [...accounts.values()] };
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPortfolioHistory(): Promise<PortfolioHistoryResponse> {
|
||||||
|
const { rows } = await pool.query<PortfolioHistoryRow>(
|
||||||
|
`SELECT a.id AS account_id, a.alias, a.bank, a.account_number,
|
||||||
|
r.report_period_to, SUM(p.valuation) AS total_valuation
|
||||||
|
FROM accounts a
|
||||||
|
JOIN portfolio_reports r ON r.account_id = a.id
|
||||||
|
LEFT JOIN portfolio_positions p ON p.report_id = r.id
|
||||||
|
WHERE a.account_type IN ('brokerage', 'iis')
|
||||||
|
GROUP BY a.id, a.alias, a.bank, a.account_number, r.id, r.report_period_to, r.reported_at, r.imported_at
|
||||||
|
ORDER BY a.id, r.report_period_to, r.reported_at, r.imported_at, r.id`,
|
||||||
|
);
|
||||||
|
return toPortfolioHistory(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
type Lot = { quantity: number; cost: number };
|
||||||
|
|
||||||
|
export function calculatePortfolioTradeResults(trades: PerformanceTradeRow[], positions: PerformancePositionRow[]): Map<number, { fees: number; realized: number; unrealized: number | null }> {
|
||||||
|
const result = new Map<number, { fees: number; realized: number; unrealized: number | null }>();
|
||||||
|
const lots = new Map<string, Lot[]>();
|
||||||
|
for (const trade of trades) {
|
||||||
|
const accountId = Number(trade.account_id);
|
||||||
|
const current = result.get(accountId) ?? { fees: 0, realized: 0, unrealized: null };
|
||||||
|
const quantity = Number(trade.quantity);
|
||||||
|
const amount = Number(trade.settlement_amount ?? 0);
|
||||||
|
const fees = Number(trade.settlement_commission ?? 0) + Number(trade.trade_commission ?? 0);
|
||||||
|
current.fees += fees;
|
||||||
|
const key = `${accountId}:${trade.isin ?? trade.instrument}`;
|
||||||
|
const queue = lots.get(key) ?? [];
|
||||||
|
if (/продаж/i.test(trade.side)) {
|
||||||
|
let remaining = quantity;
|
||||||
|
let matchedCost = 0;
|
||||||
|
while (remaining > 0 && queue.length > 0) {
|
||||||
|
const lot = queue[0];
|
||||||
|
const used = Math.min(remaining, lot.quantity);
|
||||||
|
const unitCost = lot.cost / lot.quantity;
|
||||||
|
matchedCost += used * unitCost;
|
||||||
|
lot.cost -= used * unitCost;
|
||||||
|
lot.quantity -= used;
|
||||||
|
remaining -= used;
|
||||||
|
if (lot.quantity <= 0) queue.shift();
|
||||||
|
}
|
||||||
|
const matched = quantity - remaining;
|
||||||
|
current.realized += matched > 0 ? (amount - fees) * (matched / quantity) - matchedCost : 0;
|
||||||
|
} else if (/покуп/i.test(trade.side) && quantity > 0) {
|
||||||
|
queue.push({ quantity, cost: amount + fees });
|
||||||
|
}
|
||||||
|
lots.set(key, queue);
|
||||||
|
result.set(accountId, current);
|
||||||
|
}
|
||||||
|
const incomplete = new Set<number>();
|
||||||
|
for (const position of positions) {
|
||||||
|
const accountId = Number(position.account_id);
|
||||||
|
const current = result.get(accountId) ?? { fees: 0, realized: 0, unrealized: 0 };
|
||||||
|
if (position.valuation !== null) {
|
||||||
|
const key = `${accountId}:${position.isin ?? position.instrument}`;
|
||||||
|
const queue = lots.get(key) ?? [];
|
||||||
|
let remaining = Number(position.quantity);
|
||||||
|
let cost = 0;
|
||||||
|
for (const lot of queue) {
|
||||||
|
if (remaining <= 0) break;
|
||||||
|
const used = Math.min(remaining, lot.quantity);
|
||||||
|
cost += used * (lot.cost / lot.quantity);
|
||||||
|
remaining -= used;
|
||||||
|
}
|
||||||
|
if (remaining > 0.0000001) incomplete.add(accountId);
|
||||||
|
else if (!incomplete.has(accountId)) current.unrealized = (current.unrealized ?? 0) + Number(position.valuation) - cost;
|
||||||
|
}
|
||||||
|
result.set(accountId, current);
|
||||||
|
}
|
||||||
|
for (const accountId of incomplete) {
|
||||||
|
const current = result.get(accountId);
|
||||||
|
if (current) current.unrealized = null;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPortfolioPerformance(): Promise<PortfolioPerformanceResponse> {
|
||||||
|
const [cashResult, tradeResult, positionResult] = await Promise.all([
|
||||||
|
pool.query<PerformanceCashRow>(`SELECT t.id, a.id AS account_id, a.alias, a.bank, a.account_number, a.account_type, t.operation_at, t.amount_signed, t.description FROM accounts a JOIN transactions t ON t.account_id = a.id ORDER BY a.id, t.operation_at, t.id`),
|
||||||
|
pool.query<PerformanceTradeRow>(`SELECT account_id, side, quantity, settlement_amount, settlement_commission, trade_commission, isin, instrument FROM portfolio_trades ORDER BY account_id, concluded_at, id`),
|
||||||
|
pool.query<PerformancePositionRow>(`SELECT r.account_id, p.quantity, p.valuation, p.isin, p.instrument FROM portfolio_reports r JOIN portfolio_positions p ON p.report_id = r.id JOIN LATERAL (SELECT id FROM portfolio_reports WHERE account_id = r.account_id ORDER BY report_period_to DESC, imported_at DESC, id DESC LIMIT 1) latest ON latest.id = r.id`),
|
||||||
|
]);
|
||||||
|
const tradeMap = calculatePortfolioTradeResults(tradeResult.rows, positionResult.rows);
|
||||||
|
const accounts = new Map<number, PortfolioPerformanceResponse['accounts'][number]>();
|
||||||
|
const brokerRows = cashResult.rows.filter((item) => ['brokerage', 'iis'].includes(item.account_type ?? ''));
|
||||||
|
const matchedBrokerTransfers = matchExternalCashTransfers(cashResult.rows);
|
||||||
|
const accountByReference = new Map(brokerRows.map((row) => [Number(row.account_id), row.account_number.replace(/\D/g, '')]));
|
||||||
|
for (const row of brokerRows) {
|
||||||
|
const accountId = Number(row.account_id);
|
||||||
|
const account = accounts.get(accountId) ?? { accountId, accountName: row.alias || `${row.bank} · ${maskAccountNumber(row.account_number)}`, contributions: 0, withdrawals: 0, income: 0, fees: 0, realizedResult: 0, unrealizedResult: null };
|
||||||
|
const amount = Number(row.amount_signed);
|
||||||
|
const kind = classifyPortfolioCash(amount, row.description, amount > 0 && matchedBrokerTransfers.has(row.id));
|
||||||
|
if (kind === 'income') account.income += amount;
|
||||||
|
else if (kind === 'contribution') account.contributions += amount;
|
||||||
|
accounts.set(accountId, account);
|
||||||
|
}
|
||||||
|
for (const row of cashResult.rows.filter((item) => !['brokerage', 'iis'].includes(item.account_type ?? '') && Number(item.amount_signed) > 0)) {
|
||||||
|
const reference = extractBrokerWithdrawalAccount(row.description);
|
||||||
|
if (!reference) continue;
|
||||||
|
const accountEntry = [...accountByReference.entries()].find(([, accountNumber]) => accountNumber.endsWith(reference) || reference.endsWith(accountNumber));
|
||||||
|
if (!accountEntry) continue;
|
||||||
|
const accountId = accountEntry[0];
|
||||||
|
const source = brokerRows.find((item) => Number(item.account_id) === accountId);
|
||||||
|
const account = accounts.get(accountId) ?? { accountId, accountName: source?.alias || `${source?.bank ?? 'Брокерский счёт'} · ${maskAccountNumber(source?.account_number ?? reference)}`, contributions: 0, withdrawals: 0, income: 0, fees: 0, realizedResult: 0, unrealizedResult: null };
|
||||||
|
account.withdrawals += Number(row.amount_signed);
|
||||||
|
accounts.set(accountId, account);
|
||||||
|
}
|
||||||
|
for (const [accountId, values] of tradeMap) {
|
||||||
|
const account = accounts.get(accountId) ?? { accountId, accountName: `Счёт ${accountId}`, contributions: 0, withdrawals: 0, income: 0, fees: 0, realizedResult: 0, unrealizedResult: null };
|
||||||
|
account.fees = Math.round(values.fees * 100);
|
||||||
|
account.realizedResult = Math.round(values.realized * 100);
|
||||||
|
account.unrealizedResult = values.unrealized === null ? null : Math.round(values.unrealized * 100);
|
||||||
|
accounts.set(accountId, account);
|
||||||
|
}
|
||||||
|
return { accounts: [...accounts.values()] };
|
||||||
|
}
|
||||||
|
|||||||
46
backend/src/services/portfolioOverview.test.ts
Normal file
46
backend/src/services/portfolioOverview.test.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { calculatePortfolioTradeResults, classifyPortfolioCash, extractBrokerWithdrawalAccount, matchExternalCashTransfers, sumKnownPortfolioValuations, toPortfolioHistory, toPortfolioOverview } from './portfolio';
|
||||||
|
|
||||||
|
const result = toPortfolioOverview([
|
||||||
|
{ account_id: '1', alias: 'ИИС', bank: 'ВТБ', account_number: '123456', report_period_to: '2026-08-26', total_valuation: '150.50', instrument: 'Облигация', isin: 'RU0000000001', quantity: '1', price: '100', valuation: '100' },
|
||||||
|
{ account_id: '1', alias: 'ИИС', bank: 'ВТБ', account_number: '123456', report_period_to: '2026-08-26', total_valuation: '150.50', instrument: 'Фонд', isin: null, quantity: '2', price: '25.25', valuation: '50.50' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.equal(result.accounts[0].accountName, 'ИИС');
|
||||||
|
assert.equal(result.accounts[0].totalValuation, '150.50');
|
||||||
|
assert.equal(result.accounts[0].positions.length, 2);
|
||||||
|
console.log('portfolio overview: OK');
|
||||||
|
|
||||||
|
const history = toPortfolioHistory([
|
||||||
|
{ account_id: '1', alias: 'ИИС', bank: 'ВТБ', account_number: '123456', report_period_to: '2026-08-20', total_valuation: '100' },
|
||||||
|
{ account_id: '1', alias: 'ИИС', bank: 'ВТБ', account_number: '123456', report_period_to: '2026-08-26', total_valuation: '150.50' },
|
||||||
|
]);
|
||||||
|
assert.deepEqual(history.accounts[0].points.map((point) => point.totalValuation), ['100', '150.50']);
|
||||||
|
console.log('portfolio history: OK');
|
||||||
|
|
||||||
|
const tradeResults = calculatePortfolioTradeResults([
|
||||||
|
{ account_id: 1, side: 'Покупка', quantity: '2', settlement_amount: '200', settlement_commission: '1', trade_commission: '1', isin: 'RU1', instrument: 'Фонд' },
|
||||||
|
{ account_id: 1, side: 'Продажа', quantity: '1', settlement_amount: '150', settlement_commission: '1', trade_commission: '0', isin: 'RU1', instrument: 'Фонд' },
|
||||||
|
], [{ account_id: 1, quantity: '1', valuation: '130', isin: 'RU1', instrument: 'Фонд' }]);
|
||||||
|
assert.equal(tradeResults.get(1)?.fees, 3);
|
||||||
|
assert.equal(tradeResults.get(1)?.realized, 48);
|
||||||
|
assert.equal(tradeResults.get(1)?.unrealized, 29);
|
||||||
|
console.log('portfolio performance: OK');
|
||||||
|
|
||||||
|
assert.equal(classifyPortfolioCash(-12500, 'Перечисление денежных средств со счёта'), 'withdrawal');
|
||||||
|
assert.equal(classifyPortfolioCash(-12500, 'Перевод денежных средств под нерассчитанные сделки'), 'other');
|
||||||
|
assert.equal(classifyPortfolioCash(52000, 'Зачисление денежных средств для приобретения ценных бумаг'), 'other');
|
||||||
|
assert.equal(classifyPortfolioCash(52000, 'Зачисление денежных средств для приобретения ценных бумаг', true), 'contribution');
|
||||||
|
assert.equal(classifyPortfolioCash(52000, 'Пополнение брокерского счёта'), 'contribution');
|
||||||
|
assert.equal(classifyPortfolioCash(-129000, 'Вывод ДС под нерассчитанные сделки', true), 'withdrawal');
|
||||||
|
assert.equal(classifyPortfolioCash(-129000, 'Сальдо расчетов по сделкам с ценными бумагами', true), 'withdrawal');
|
||||||
|
assert.equal(extractBrokerWithdrawalAccount('Перевод между своими счетами. Вывод денежных средств с брокерского счета 30601 по распоряжению от 2026-05-12.'), '30601');
|
||||||
|
assert.equal(extractBrokerWithdrawalAccount('Вывод денежных средств с брокерского счёта 30601'), '30601');
|
||||||
|
assert.equal(sumKnownPortfolioValuations([100, null, 25]), 125);
|
||||||
|
const matched = matchExternalCashTransfers([
|
||||||
|
{ id: 1, account_id: 1, alias: null, bank: 'VTB', account_number: 'broker', account_type: 'brokerage', operation_at: '2026-05-12T00:00:00+03:00', amount_signed: '-5102321', description: 'Нестандартное описание операции' },
|
||||||
|
{ id: 2, account_id: 1, alias: null, bank: 'VTB', account_number: 'broker', account_type: 'brokerage', operation_at: '2026-05-13T00:00:00+03:00', amount_signed: '-4885479', description: 'Вывод ДС под нерассчитанные сделки' },
|
||||||
|
{ id: 3, account_id: 2, alias: null, bank: 'VTB', account_number: 'current', account_type: 'current', operation_at: '2026-05-12T00:00:00+03:00', amount_signed: '9987800', description: 'Вывод денежных средств с брокерского счета' },
|
||||||
|
]);
|
||||||
|
assert.deepEqual([...matched], [1, 2]);
|
||||||
|
console.log('portfolio cash classification: OK');
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@family-budget/frontend",
|
"name": "@family-budget/frontend",
|
||||||
"version": "0.12.0",
|
"version": "0.16.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
|
"test:portfolio": "tsx src/api/portfolio.test.ts",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { LoginPage } from './pages/LoginPage';
|
|||||||
import { HistoryPage } from './pages/HistoryPage';
|
import { HistoryPage } from './pages/HistoryPage';
|
||||||
import { AnalyticsPage } from './pages/AnalyticsPage';
|
import { AnalyticsPage } from './pages/AnalyticsPage';
|
||||||
import { SettingsPage } from './pages/SettingsPage';
|
import { SettingsPage } from './pages/SettingsPage';
|
||||||
|
import { PortfolioPage } from './pages/PortfolioPage';
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
const { user, loading } = useAuth();
|
const { user, loading } = useAuth();
|
||||||
@@ -23,6 +24,7 @@ export function App() {
|
|||||||
<Route path="/" element={<Navigate to="/history" replace />} />
|
<Route path="/" element={<Navigate to="/history" replace />} />
|
||||||
<Route path="/history" element={<HistoryPage />} />
|
<Route path="/history" element={<HistoryPage />} />
|
||||||
<Route path="/analytics" element={<AnalyticsPage />} />
|
<Route path="/analytics" element={<AnalyticsPage />} />
|
||||||
|
<Route path="/portfolio" element={<PortfolioPage />} />
|
||||||
<Route path="/settings" element={<SettingsPage />} />
|
<Route path="/settings" element={<SettingsPage />} />
|
||||||
<Route path="*" element={<Navigate to="/history" replace />} />
|
<Route path="*" element={<Navigate to="/history" replace />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
17
frontend/src/api/portfolio.test.ts
Normal file
17
frontend/src/api/portfolio.test.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { getPortfolioHistory, getPortfolioOverview, getPortfolioPerformance } from './portfolio';
|
||||||
|
|
||||||
|
const calls: string[] = [];
|
||||||
|
const originalFetch = globalThis.fetch;
|
||||||
|
globalThis.fetch = async (input) => {
|
||||||
|
calls.push(String(input));
|
||||||
|
return new Response(JSON.stringify({ accounts: [] }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
await Promise.all([getPortfolioOverview(), getPortfolioHistory(), getPortfolioPerformance()]);
|
||||||
|
assert.deepEqual(calls.sort(), ['/api/portfolio', '/api/portfolio/history', '/api/portfolio/performance']);
|
||||||
|
console.log('portfolio API contract: OK');
|
||||||
|
} finally {
|
||||||
|
globalThis.fetch = originalFetch;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { ImportBrokerReportResponse, ImportPortfolioResponse, PortfolioFile } from '@family-budget/shared';
|
import type { ImportBrokerReportResponse, ImportPortfolioResponse, PortfolioFile, PortfolioHistoryResponse, PortfolioOverviewResponse, PortfolioPerformanceResponse } from '@family-budget/shared';
|
||||||
import { api } from './client';
|
import { api } from './client';
|
||||||
|
|
||||||
export function importPortfolio(data: PortfolioFile): Promise<ImportPortfolioResponse> {
|
export function importPortfolio(data: PortfolioFile): Promise<ImportPortfolioResponse> {
|
||||||
@@ -10,3 +10,15 @@ export function importBrokerReport(file: File): Promise<ImportBrokerReportRespon
|
|||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
return api.postFormData('/api/import/broker', formData);
|
return api.postFormData('/api/import/broker', formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getPortfolioOverview(): Promise<PortfolioOverviewResponse> {
|
||||||
|
return api.get('/api/portfolio');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPortfolioHistory(): Promise<PortfolioHistoryResponse> {
|
||||||
|
return api.get('/api/portfolio/history');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPortfolioPerformance(): Promise<PortfolioPerformanceResponse> {
|
||||||
|
return api.get('/api/portfolio/performance');
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,6 +63,21 @@ export function Layout({ children }: { children: ReactNode }) {
|
|||||||
Операции
|
Операции
|
||||||
</NavLink>
|
</NavLink>
|
||||||
|
|
||||||
|
<NavLink
|
||||||
|
to="/portfolio"
|
||||||
|
className={({ isActive }) =>
|
||||||
|
`sidebar__nav-link${isActive ? ' sidebar__nav-link--active' : ''}`
|
||||||
|
}
|
||||||
|
onClick={closeDrawer}
|
||||||
|
>
|
||||||
|
<svg className="sidebar__nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
||||||
|
<path d="M3 21h18" />
|
||||||
|
<path d="M5 21V10l7-5 7 5v11" />
|
||||||
|
<path d="M9 21v-6h6v6" />
|
||||||
|
</svg>
|
||||||
|
Портфель
|
||||||
|
</NavLink>
|
||||||
|
|
||||||
<NavLink
|
<NavLink
|
||||||
to="/analytics"
|
to="/analytics"
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
|
|||||||
96
frontend/src/pages/PortfolioPage.tsx
Normal file
96
frontend/src/pages/PortfolioPage.tsx
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
|
||||||
|
import type { PortfolioHistoryResponse, PortfolioOverviewResponse, PortfolioPerformanceResponse } from '@family-budget/shared';
|
||||||
|
import { getPortfolioHistory, getPortfolioOverview, getPortfolioPerformance } from '../api/portfolio';
|
||||||
|
import { formatDate } from '../utils/format';
|
||||||
|
|
||||||
|
const money = new Intl.NumberFormat('ru-RU', { style: 'currency', currency: 'RUB', minimumFractionDigits: 2 });
|
||||||
|
const number = new Intl.NumberFormat('ru-RU', { maximumFractionDigits: 6 });
|
||||||
|
|
||||||
|
export function PortfolioPage() {
|
||||||
|
const [data, setData] = useState<PortfolioOverviewResponse | null>(null);
|
||||||
|
const [history, setHistory] = useState<PortfolioHistoryResponse | null>(null);
|
||||||
|
const [performance, setPerformance] = useState<PortfolioPerformanceResponse | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getPortfolioOverview().then(setData).catch(() => {});
|
||||||
|
getPortfolioHistory().then(setHistory).catch(() => {});
|
||||||
|
getPortfolioPerformance().then(setPerformance).catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="page">
|
||||||
|
<div className="page__header">
|
||||||
|
<div>
|
||||||
|
<p className="page__eyebrow">Инвестиции</p>
|
||||||
|
<h1 className="page__title">Портфель</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!data ? <div className="state">Загрузка...</div> : data.accounts.length === 0 ? (
|
||||||
|
<div className="state state--empty">Портфель пока пуст. Загрузите XLSX-отчёт брокера в разделе «Операции».</div>
|
||||||
|
) : data.accounts.map((account) => (
|
||||||
|
<section className="portfolio" key={account.accountId} aria-labelledby={`portfolio-${account.accountId}`}>
|
||||||
|
<div className="portfolio__header">
|
||||||
|
<div>
|
||||||
|
<h2 id={`portfolio-${account.accountId}`} className="portfolio__title">{account.accountName}</h2>
|
||||||
|
<p className="portfolio__meta">{account.valuationSource === 'mixed' ? 'Часть позиций по последнему отчёту' : account.valuationSource === 'report' ? `Стоимость по отчёту на ${formatDate(account.reportPeriodTo)}` : `Котировки на ${formatDate(account.valuationAsOf ?? account.reportPeriodTo)}`}</p>
|
||||||
|
</div>
|
||||||
|
{(account.currentValuation ?? account.totalValuation) !== null && <strong className="portfolio__total">{money.format(Number(account.currentValuation ?? account.totalValuation))}</strong>}
|
||||||
|
</div>
|
||||||
|
{account.positions.length === 0 ? <div className="state state--empty">В последнем отчёте нет открытых позиций.</div> : (
|
||||||
|
<div className="table-shell">
|
||||||
|
<table className="data-table">
|
||||||
|
<thead><tr><th className="data-table__head-cell" scope="col">Инструмент</th><th className="data-table__head-cell" scope="col">Количество</th><th className="data-table__head-cell" scope="col">Цена</th><th className="data-table__head-cell" scope="col">Стоимость</th></tr></thead>
|
||||||
|
<tbody className="data-table__body">
|
||||||
|
{account.positions.map((position, index) => <tr className="data-table__row" key={`${position.isin ?? position.instrument}-${index}`}>
|
||||||
|
<td className="data-table__cell"><div className="data-table__description">{position.instrument}</div>{position.isin && <div className="data-table__subtext">{position.isin}</div>}</td>
|
||||||
|
<td className="data-table__cell data-table__cell--nowrap">{number.format(Number(position.quantity))}</td>
|
||||||
|
<td className="data-table__cell data-table__cell--nowrap">{(position.currentPrice ?? position.price) === null ? '—' : money.format(Number(position.currentPrice ?? position.price))}</td>
|
||||||
|
<td className="data-table__cell data-table__cell--nowrap money-amount">{(position.currentValuation ?? position.valuation) === null ? '—' : money.format(Number(position.currentValuation ?? position.valuation))}</td>
|
||||||
|
</tr>)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{history?.accounts.map((account) => account.points.length > 1 && (
|
||||||
|
<section className="portfolio" key={`history-${account.accountId}`} aria-labelledby={`history-${account.accountId}`}>
|
||||||
|
<div className="portfolio__header">
|
||||||
|
<div>
|
||||||
|
<h2 id={`history-${account.accountId}`} className="portfolio__title">Динамика · {account.accountName}</h2>
|
||||||
|
<p className="portfolio__meta">Стоимость по загруженным отчётам</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="chart-card portfolio__chart">
|
||||||
|
<ResponsiveContainer width="100%" height={280}>
|
||||||
|
<LineChart data={account.points.map((point) => ({ date: point.reportPeriodTo, value: point.totalValuation === null ? null : Number(point.totalValuation) }))}>
|
||||||
|
<CartesianGrid strokeDasharray="3 3" stroke="var(--color-border)" vertical={false} />
|
||||||
|
<XAxis dataKey="date" tickFormatter={(value: string) => formatDate(value)} fontSize={12} stroke="var(--color-text-secondary)" tickLine={false} axisLine={false} />
|
||||||
|
<YAxis tickFormatter={(value: number) => `${Math.round(value / 1000)}к`} fontSize={12} stroke="var(--color-text-secondary)" tickLine={false} axisLine={false} />
|
||||||
|
<Tooltip labelFormatter={(value) => formatDate(String(value))} formatter={(value) => value == null ? '—' : money.format(Number(value))} />
|
||||||
|
<Line type="monotone" dataKey="value" name="Стоимость" stroke="var(--color-primary)" strokeWidth={2} dot={{ r: 3 }} connectNulls />
|
||||||
|
</LineChart>
|
||||||
|
</ResponsiveContainer>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
|
||||||
|
{performance?.accounts.map((account) => (
|
||||||
|
<section className="portfolio" key={`performance-${account.accountId}`} aria-labelledby={`performance-${account.accountId}`}>
|
||||||
|
<h2 id={`performance-${account.accountId}`} className="portfolio__title">Результат · {account.accountName}</h2>
|
||||||
|
<div className="summary portfolio__performance">
|
||||||
|
<div className="summary__card summary__card--investments"><div className="summary__label">Пополнения</div><div className="summary__value">{money.format(account.contributions / 100)}</div></div>
|
||||||
|
<div className="summary__card summary__card--investments"><div className="summary__label">Выводы</div><div className="summary__value">{money.format(account.withdrawals / 100)}</div></div>
|
||||||
|
<div className="summary__card summary__card--income"><div className="summary__label">Купоны, дивиденды и проценты</div><div className="summary__value">{money.format(account.income / 100)}</div></div>
|
||||||
|
<div className="summary__card summary__card--expense"><div className="summary__label">Комиссии</div><div className="summary__value">{money.format(account.fees / 100)}</div></div>
|
||||||
|
<div className="summary__card summary__card--positive"><div className="summary__label">Результат продаж</div><div className="summary__value">{money.format(account.realizedResult / 100)}</div></div>
|
||||||
|
{account.unrealizedResult !== null && <div className="summary__card summary__card--positive"><div className="summary__label">Нереализованный результат</div><div className="summary__value">{money.format(account.unrealizedResult / 100)}</div></div>}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -341,6 +341,38 @@ button {
|
|||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.portfolio {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.portfolio__header {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.portfolio__title {
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 850;
|
||||||
|
}
|
||||||
|
|
||||||
|
.portfolio__meta {
|
||||||
|
margin-top: 3px;
|
||||||
|
color: var(--color-text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.portfolio__total {
|
||||||
|
font-size: 20px;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
|
|
||||||
|
.portfolio__chart {
|
||||||
|
min-height: 280px;
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================================
|
/* ================================================================
|
||||||
Forms, buttons, badges
|
Forms, buttons, badges
|
||||||
================================================================ */
|
================================================================ */
|
||||||
@@ -1462,6 +1494,11 @@ input[type="checkbox"] {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.portfolio__header {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
.filters__row,
|
.filters__row,
|
||||||
.analytics-panel__filters {
|
.analytics-panel__filters {
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
|||||||
45
package-lock.json
generated
45
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "family-budget",
|
"name": "family-budget",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "family-budget",
|
"name": "family-budget",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"shared",
|
"shared",
|
||||||
"backend",
|
"backend",
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"backend": {
|
"backend": {
|
||||||
"name": "@family-budget/backend",
|
"name": "@family-budget/backend",
|
||||||
"version": "0.1.0",
|
"version": "0.15.6",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@family-budget/shared": "*",
|
"@family-budget/shared": "*",
|
||||||
"cookie-parser": "^1.4.7",
|
"cookie-parser": "^1.4.7",
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
},
|
},
|
||||||
"frontend": {
|
"frontend": {
|
||||||
"name": "@family-budget/frontend",
|
"name": "@family-budget/frontend",
|
||||||
"version": "0.9.0",
|
"version": "0.16.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@family-budget/shared": "*",
|
"@family-budget/shared": "*",
|
||||||
"react": "^19.0.0",
|
"react": "^19.0.0",
|
||||||
@@ -111,7 +111,6 @@
|
|||||||
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.29.0",
|
"@babel/code-frame": "^7.29.0",
|
||||||
"@babel/generator": "^7.29.0",
|
"@babel/generator": "^7.29.0",
|
||||||
@@ -1395,7 +1394,6 @@
|
|||||||
"integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==",
|
"integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/body-parser": "*",
|
"@types/body-parser": "*",
|
||||||
"@types/express-serve-static-core": "^5.0.0",
|
"@types/express-serve-static-core": "^5.0.0",
|
||||||
@@ -1474,7 +1472,6 @@
|
|||||||
"integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==",
|
"integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"csstype": "^3.2.2"
|
"csstype": "^3.2.2"
|
||||||
}
|
}
|
||||||
@@ -1614,7 +1611,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.9.0",
|
"baseline-browser-mapping": "^2.9.0",
|
||||||
"caniuse-lite": "^1.0.30001759",
|
"caniuse-lite": "^1.0.30001759",
|
||||||
@@ -2738,7 +2734,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.19.0.tgz",
|
"resolved": "https://registry.npmjs.org/pg/-/pg-8.19.0.tgz",
|
||||||
"integrity": "sha512-QIcLGi508BAHkQ3pJNptsFz5WQMlpGbuBGBaIaXsWK8mel2kQ/rThYI+DbgjUvZrIr7MiuEuc9LcChJoEZK1xQ==",
|
"integrity": "sha512-QIcLGi508BAHkQ3pJNptsFz5WQMlpGbuBGBaIaXsWK8mel2kQ/rThYI+DbgjUvZrIr7MiuEuc9LcChJoEZK1xQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pg-connection-string": "^2.11.0",
|
"pg-connection-string": "^2.11.0",
|
||||||
"pg-pool": "^3.12.0",
|
"pg-pool": "^3.12.0",
|
||||||
@@ -2836,7 +2831,6 @@
|
|||||||
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@@ -2986,7 +2980,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react/-/react-19.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/react/-/react-19.2.4.tgz",
|
||||||
"integrity": "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ==",
|
"integrity": "sha512-9nfp2hYpCwOjAN+8TZFGhtWEwgvWHXqESH8qT89AT/lWklpLON22Lc8pEtnpsZz7VmawabSU0gCjnj8aC0euHQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -2996,7 +2989,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.4.tgz",
|
||||||
"integrity": "sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ==",
|
"integrity": "sha512-AXJdLo8kgMbimY95O2aKQqsz2iWi9jMgKJhRBAxECE4IFxfcazB2LmzloIoibJI3C12IlY20+KFaLv+71bUJeQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"scheduler": "^0.27.0"
|
"scheduler": "^0.27.0"
|
||||||
},
|
},
|
||||||
@@ -3500,6 +3492,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"aix"
|
"aix"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3517,6 +3510,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3534,6 +3528,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3551,6 +3546,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"android"
|
"android"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3568,6 +3564,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3585,6 +3582,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"darwin"
|
"darwin"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3602,6 +3600,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"freebsd"
|
"freebsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3619,6 +3618,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"freebsd"
|
"freebsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3636,6 +3636,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3653,6 +3654,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3670,6 +3672,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3687,6 +3690,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3704,6 +3708,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3721,6 +3726,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3738,6 +3744,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3755,6 +3762,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3772,6 +3780,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"linux"
|
"linux"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3789,6 +3798,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"netbsd"
|
"netbsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3806,6 +3816,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"netbsd"
|
"netbsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3823,6 +3834,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"openbsd"
|
"openbsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3840,6 +3852,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"openbsd"
|
"openbsd"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3857,6 +3870,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"openharmony"
|
"openharmony"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3874,6 +3888,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"sunos"
|
"sunos"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3891,6 +3906,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3908,6 +3924,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -3925,6 +3942,7 @@
|
|||||||
"os": [
|
"os": [
|
||||||
"win32"
|
"win32"
|
||||||
],
|
],
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18"
|
"node": ">=18"
|
||||||
}
|
}
|
||||||
@@ -4108,7 +4126,6 @@
|
|||||||
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.25.0",
|
"esbuild": "^0.25.0",
|
||||||
"fdir": "^6.4.4",
|
"fdir": "^6.4.4",
|
||||||
@@ -4202,7 +4219,7 @@
|
|||||||
},
|
},
|
||||||
"shared": {
|
"shared": {
|
||||||
"name": "@family-budget/shared",
|
"name": "@family-budget/shared",
|
||||||
"version": "0.1.0",
|
"version": "0.10.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.7.0"
|
"typescript": "^5.7.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@family-budget/shared",
|
"name": "@family-budget/shared",
|
||||||
"version": "0.6.0",
|
"version": "0.10.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -98,3 +98,59 @@ export interface ImportBrokerReportResponse {
|
|||||||
cash: ImportStatementResponse;
|
cash: ImportStatementResponse;
|
||||||
portfolio: ImportPortfolioResponse;
|
portfolio: ImportPortfolioResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PortfolioOverviewPosition {
|
||||||
|
instrument: string;
|
||||||
|
isin: string | null;
|
||||||
|
quantity: string;
|
||||||
|
price: string | null;
|
||||||
|
valuation: string | null;
|
||||||
|
currentPrice?: string | null;
|
||||||
|
currentValuation?: string | null;
|
||||||
|
quoteAt?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioOverviewAccount {
|
||||||
|
accountId: number;
|
||||||
|
accountName: string;
|
||||||
|
reportPeriodTo: string;
|
||||||
|
totalValuation: string | null;
|
||||||
|
currentValuation?: string | null;
|
||||||
|
valuationAsOf?: string | null;
|
||||||
|
valuationSource?: 'market' | 'mixed' | 'report';
|
||||||
|
positions: PortfolioOverviewPosition[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioOverviewResponse {
|
||||||
|
accounts: PortfolioOverviewAccount[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioHistoryPoint {
|
||||||
|
reportPeriodTo: string;
|
||||||
|
totalValuation: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioHistoryAccount {
|
||||||
|
accountId: number;
|
||||||
|
accountName: string;
|
||||||
|
points: PortfolioHistoryPoint[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioHistoryResponse {
|
||||||
|
accounts: PortfolioHistoryAccount[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioPerformanceAccount {
|
||||||
|
accountId: number;
|
||||||
|
accountName: string;
|
||||||
|
contributions: number;
|
||||||
|
withdrawals: number;
|
||||||
|
income: number;
|
||||||
|
fees: number;
|
||||||
|
realizedResult: number;
|
||||||
|
unrealizedResult: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PortfolioPerformanceResponse {
|
||||||
|
accounts: PortfolioPerformanceAccount[];
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ export type {
|
|||||||
PortfolioTrade,
|
PortfolioTrade,
|
||||||
ImportPortfolioResponse,
|
ImportPortfolioResponse,
|
||||||
ImportBrokerReportResponse,
|
ImportBrokerReportResponse,
|
||||||
|
PortfolioOverviewPosition,
|
||||||
|
PortfolioOverviewAccount,
|
||||||
|
PortfolioOverviewResponse,
|
||||||
|
PortfolioHistoryPoint,
|
||||||
|
PortfolioHistoryAccount,
|
||||||
|
PortfolioHistoryResponse,
|
||||||
|
PortfolioPerformanceAccount,
|
||||||
|
PortfolioPerformanceResponse,
|
||||||
} from './import';
|
} from './import';
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
|
|||||||
Reference in New Issue
Block a user