Codex provides wallet-level profit and loss data across several endpoints, includingDocumentation Index
Fetch the complete documentation index at: https://docs.codex.io/llms.txt
Use this file to discover all available pages before exploring further.
filterWallets, filterTokenWallets, getDetailedWalletStats, and walletChart. This page covers how those PnL numbers are calculated so you can interpret them correctly and layer on additional adjustments where needed.
Cost basis methodology
Codex calculates realized PnL using weighted average cost basis. Each buy adds to a cumulative acquisition cost, and each sell reduces that cost proportionally based on the share of holdings sold. The formula forrealizedPnl:
Worked example
A wallet trades a token called PENGU:| Action | Running acquisition cost | Tokens held | Realized PnL |
|---|---|---|---|
| Buy 10 PENGU for $10 | $10 | 10 | $0 |
| Sell 4 PENGU for $8 | $6 | 6 | +$4 |
| Buy 10 PENGU for $20 | $26 | 16 | +$4 (unchanged) |
| Sell 16 PENGU for $32 | $0 | 0 | +$10 |
Fee handling
Wallet PnL and volume figures handle fees in two different ways depending on the fee type.Pool and swap fees
Pool fees are already reflected inrealizedProfitUsd and volumeUsd. Codex reads swap values post-execution, so the amounts and prices recorded are net of what the pool took. No additional adjustment is needed on your end.
Gas fees
Gas fees (base fees, priority fees, L1 data fees, and builder tips) are tracked separately from wallet PnL. Gas is paid outside the swap itself, so wallet aggregation does not fold it intorealizedProfitUsd or volumeUsd.
If you want PnL net of gas, subtract gas fees yourself using the Global Fees Paid (GFP) fields. GFP exposes per-event and per-window fee components across most endpoints that return swap or bar data.
Data freshness
Wallet stats are indexed and updated on a rolling basis. To keep frequently viewed wallets fresh, queryingfilterWallets or filterTokenWallets with one or more specific wallet addresses triggers a background refresh of the 500 most recently traded tokens for each wallet. Refreshes are capped at once every 6 hours per wallet.
The triggering request returns the current indexed data immediately. Refreshed values become available shortly after, so a follow-up query will reflect the updated stats.
Related
- Global Fees Paid — fee components available across endpoints
- Wallets recipe — practical examples of querying wallet data
filterWallets,filterTokenWallets,getDetailedWalletStats,walletChart