Skip to main content
What you’ll build
  • A wallet’s total PnL: realized, unrealized, fees and external flows
  • Per-token breakdowns for up to 100 tokens in one call
  • The same token’s performance compared across chains
  • PnL for a specific time range
  • Handling for edge cases like the 503 bootstrap and airdrops
Time
~10 minutes
You need

How PnL is calculated

Zerion API uses FIFO (first in, first out): it matches the earliest purchases against the earliest sales. This is the most common standard for tax reporting.

Response fields

When you add token filters (fungible_ids or fungible_implementations), the response also includes a breakdown object with per-token stats like average_buy_price, average_sell_price, and gain percentages.
The resource type in the response is wallet_pnl (not pnl).

Steps

1

Portfolio-level PnL

Fetch a wallet’s overall PnL across all tokens and chains.GET /v1/wallets/{address}/pnl?currency=usd
2

Batch PnL for specific tokens

Pass up to 100 tokens in one request to get a per-token breakdown. There are two filtering modes:Option A: fungible_ids (cross-chain)Aggregates a token’s PnL across all chains. Use it for portfolio-level token views where the chain doesn’t matter.
Example response (breakdown.by_id):
When you filter by token, the top-level fields (realized_gain, net_invested, etc.) reflect only the filtered tokens, not your entire wallet.
Option B: fungible_implementations (chain-specific)Tracks PnL per chain deployment, using chain:contract_address pairs. Use it to compare the same token across L1s and L2s, or when you need chain-level precision.
Native chain tokens use chain: with an empty address after the colon: ethereum: for ETH, base: for Base ETH, polygon: for MATIC, solana: for SOL.
Per-token breakdown fields:Each entry in the breakdown object (whether by_id or by_implementation) contains:
3

Time-range PnL

Scope PnL to a time window with the since and till parameters, as Unix timestamps in milliseconds. Omit till to measure up to now.PnL is pre-computed at six marks: now, 1 day ago, 1 week ago, 1 month ago, 1 year ago and the beginning of the year. Ranges on these marks return in under 200 ms at p99. This example uses the beginning of the year:
A since or till that isn’t on a mark works only if fewer than 3,000 transactions sit between it and the nearest mark. Otherwise the request returns 503, and retrying doesn’t help. For example, calendar year 2025 (since=1735689600000&till=1767225600000) returns 503 for vitalik.eth. On busy wallets, use the marks.
You can combine since/till with token filters.
Unrealized gains are always calculated using current market prices, regardless of the till parameter. If you set till to a past date, realized gains reflect that period, but unrealized gains use today’s prices.
4

Filter by chain

Scope PnL to specific chains with filter[chain_ids].GET /v1/wallets/{address}/pnl?currency=usd&filter[chain_ids]=ethereum,base
Use it when your app is chain-specific (for example, a Base-only wallet) or to compare PnL across L2s.
Zerion API ignores filter[chain_ids] when you use fungible_implementations. The chain is already part of each implementation string.
5

Full working example

Save as pnl-dashboard.mjs and run node pnl-dashboard.mjs. It prints the output shown at the top of this page and retries 503 responses while a cold wallet bootstraps.
pnl-dashboard.mjs

Edge cases and operational notes

For wallets that haven’t been queried before, or wallets with long transaction histories, the first request may return a 503 with a Retry-After header while PnL is being bootstrapped. This is non-billable. Retry after the indicated delay (usually a few seconds). Once bootstrapped, subsequent requests are fast: under 200 ms for basic PnL queries without a breakdown. Building a breakdown adds 150–300 ms depending on the number of tokens. Snapshots are retained for ~1 month; after that, a re-bootstrap may be triggered.A 503 always carries a Retry-After header. If you get an error without one, retrying is not the answer. See the next two entries.
Wallets with more than 1 million actions are too large for PnL to be calculated, and return 422 with no Retry-After header:
Don’t fold this into your 503 retry loop. The helper above only recurses on 503, so a 422 surfaces to the caller instead. Don’t cache it against the address either: the same wallet can return 503 again later if its cached state is rebuilt.
Zerion only calculates PnL for addresses that behave like user wallets. Zerion rejects contract addresses that aren’t recognized smart-contract wallets, burn addresses, and high-volume addresses such as exchange hot wallets before doing any work:
Smart-contract wallets are fine: Safe, Coinbase Smart Wallet and ERC-4337 accounts all work. See Error handling for the full rule.
Tokens without reliable price data are omitted from breakdown calculations rather than erroring. They won’t appear in the breakdown object.
Tokens received as “pure mints” (from the zero address or a token contract with no payment beyond gas) are assigned zero cost basis. However, many airdrops are actually distributed from a non-zero address, which causes them to be misclassified as purchases at the market price at the time of receipt. Keep this in mind when reviewing cost basis data for airdropped tokens.
Native chain tokens use chain: with an empty address after the colon: ethereum: for ETH, base: for Base ETH, polygon: for MATIC, solana: for SOL.
16 options via the currency param: usd, eur, gbp, btc, eth, krw, jpy, aud, cad, inr, nzd, try, zar, cny, chf, rub.
Max 100 tokens per request for either fungible_ids or fungible_implementations. For larger portfolios, paginate with multiple calls.

Next steps

  • Combine with wallet positions to fetch current holdings, then batch those token IDs into PnL for a complete dashboard.
  • Add balance charts to show portfolio value over time alongside PnL.
  • Set up webhooks to trigger PnL recalculations when new transactions land.