Skip to content

Commit bd7837d

Browse files
committed
feat(accounts): enhance portfolio history endpoints with detailed summaries and descriptions; update query DTO for clarity on included fields
1 parent 7c238ce commit bd7837d

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/account/controllers/accounts.controller.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ export class AccountsController {
161161
}
162162

163163
// Portfolio history endpoint - MUST come before :address route to avoid route conflict
164-
@ApiOperation({ operationId: 'getPortfolioHistory' })
164+
@ApiOperation({
165+
operationId: 'getPortfolioHistory',
166+
summary: 'Portfolio value history snapshots',
167+
description:
168+
'Returns portfolio value over time (AE balance, token values, total value). ' +
169+
'Pass include=pnl or include=pnl-range to add aggregate total_pnl data. ' +
170+
'Per-token PnL breakdown (tokens_pnl) is available via the dedicated :address/portfolio/tokens/history endpoint.',
171+
})
165172
@ApiParam({ name: 'address', type: 'string', description: 'Account address' })
166173
@ApiOkResponse({ type: [PortfolioHistorySnapshotDto] })
167174
@CacheTTL(60 * 10) // 10 minutes
@@ -198,7 +205,13 @@ export class AccountsController {
198205
});
199206
}
200207

201-
@ApiOperation({ operationId: 'getTokensPnlHistory' })
208+
@ApiOperation({
209+
operationId: 'getTokensPnlHistory',
210+
summary: 'Per-token PnL history snapshots',
211+
description:
212+
'Returns portfolio history snapshots that include the per-token PnL breakdown (tokens_pnl). ' +
213+
'PnL data is always included; pass include=pnl-range to use range-based (daily window) PnL instead of cumulative.',
214+
})
202215
@ApiParam({ name: 'address', type: 'string', description: 'Account address' })
203216
@ApiOkResponse({ type: [PortfolioHistorySnapshotDto] })
204217
@CacheTTL(60 * 10)
@@ -217,16 +230,14 @@ export class AccountsController {
217230
const requestedInterval = query.interval || 86400;
218231
const finalInterval = Math.max(requestedInterval, minimumInterval);
219232

220-
const includePnl =
221-
includeFields.includes('pnl') || includeFields.includes('pnl-range');
222233
const useRangeBasedPnl = includeFields.includes('pnl-range');
223234

224235
return await this.portfolioService.getPortfolioHistory(address, {
225236
startDate: start,
226237
endDate: end,
227238
interval: finalInterval,
228239
convertTo: query.convertTo || 'ae',
229-
includePnl,
240+
includePnl: true,
230241
useRangeBasedPnl,
231242
includeTokensPnl: true,
232243
});

src/account/dto/get-portfolio-history-query.dto.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export class GetPortfolioHistoryQueryDto {
6262
name: 'include',
6363
type: 'string',
6464
required: false,
65-
description: 'Comma-separated list of fields to include (e.g., "pnl")',
65+
description:
66+
'Comma-separated list of fields to include. ' +
67+
'"pnl" adds aggregate total_pnl, "pnl-range" uses daily-window PnL instead of cumulative. ' +
68+
'Per-token breakdown (tokens_pnl) is only available via the /portfolio/tokens/history endpoint.',
6669
example: 'pnl',
6770
})
6871
@IsOptional()

src/account/dto/portfolio-history-response.dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export class PortfolioHistorySnapshotDto {
7373

7474
@ApiProperty({
7575
description:
76-
'PNL breakdown per token (included if requested), keyed by token sale_address',
76+
'PNL breakdown per token, keyed by token sale_address. ' +
77+
'Only returned by the dedicated /portfolio/tokens/history endpoint.',
7778
type: Object,
7879
required: false,
7980
})

0 commit comments

Comments
 (0)