Open
Description
Priority: 🔴 Critical
Description
Multiple API endpoints advertised for timeframe-specific PNL calculations return placeholder messages instead of actual data. This is a core feature of the portfolio tracker that's completely missing, making it impossible to track profit/loss over time periods.
Current State
/api/portfolio/pnl/timeframe/:period
returns{"message": "PNL timeframe calculation not yet implemented"}
/api/wallets/pnl/:address/:period
returns{"message": "Wallet PNL timeframe calculation not yet implemented"}
- Database tables for PNL exist (
pnl_history
,portfolio_snapshots
) but aren't utilized - No historical price tracking mechanism in place
Expected Behavior
- API endpoints should return actual PNL calculations for requested timeframes:
- 24h: Last 24 hours profit/loss
- 7d: Last 7 days profit/loss
- 30d: Last 30 days profit/loss
- all: All-time profit/loss
- PNL should be calculated based on portfolio snapshots
- Both USD values and percentage changes should be provided
Technical Requirements
- Implement snapshot-based PNL calculation logic
- Add historical price tracking for accurate calculations
- Update API endpoints to return actual data instead of placeholders
- Ensure calculations account for:
- Token purchases/sales within timeframe
- Price changes of held tokens
- New wallet additions
Implementation Steps
// Example PNL calculation
interface PnlResponse {
period: string;
startValue: number;
endValue: number;
absoluteChange: number;
percentageChange: number;
breakdown: {
wallet: string;
pnl: number;
percentage: number;
}[];
}
Acceptance Criteria
- Both portfolio and wallet PNL endpoints return actual calculations
- Calculations are accurate based on historical snapshots
- Support for 24h, 7d, 30d, and all-time periods
- Response includes both absolute and percentage changes
- Individual wallet breakdowns included in portfolio PNL
References
- Endpoints:
src/routes/api.ts
lines with "not yet implemented" - Database schema:
src/services/database.ts
(pnl_history, portfolio_snapshots tables) - PRD Section 8: PNL Calculation Strategy
Labels
bug
, critical
, pnl
, api
, core-feature