fix: validate portfolio trade identifiers

This commit is contained in:
2026-08-20 15:04:04 +03:00
parent 6db1312fb1
commit d2354a61ed
4 changed files with 10 additions and 1 deletions

View File

@@ -29,6 +29,8 @@ export function validatePortfolio(body: unknown): asserts body is PortfolioFile
const sourceIds = new Set<string>();
for (const trade of data.trades) {
if (!trade || typeof trade.instrument !== 'string' || !trade.instrument.trim() || typeof trade.concludedAt !== 'string' || Number.isNaN(Date.parse(trade.concludedAt)) || typeof trade.side !== 'string' || !trade.side.trim()) throw new Error('Invalid trade');
if (trade.sourceId !== undefined && typeof trade.sourceId !== 'string') throw new Error('sourceId must be a string');
if (trade.operationId !== undefined && typeof trade.operationId !== 'string') throw new Error('operationId must be a string');
const sourceId = deriveTradeSourceId(trade);
if (sourceIds.has(sourceId)) throw new Error(`Duplicate sourceId: ${sourceId}`);
sourceIds.add(sourceId);