Portfolio Tracking
Track wallet positions, PnL, and token balances across Solana protocols.
Portfolio tracking applications need to aggregate data from multiple sources: token balances, DeFi positions, NFT holdings, and transaction history.
Token Balances
Use getTokenAccountsByOwner to fetch all SPL token accounts for a wallet. For Token-2022 tokens, query the Token-2022 program separately. Cache balances and update via WebSocket subscription to token account changes.
DeFi Positions
Each protocol stores position data differently. For Raydium liquidity positions, query the user's LP token accounts. For lending protocols (Solend, Marginfi), query the user's obligation accounts. For perpetuals (Drift, Zeta), query position accounts.
PnL Calculation
Calculating accurate PnL requires historical price data at the time of each transaction. Use a price oracle (Pyth, Birdeye API) to get historical prices and combine with transaction history from an indexer.
NFT Holdings
Use the DAS API (getAssetsByOwner) to fetch all NFTs for a wallet, including compressed NFTs. This provides a unified view of both regular and compressed NFT holdings.