PnL
Get the PnL for a given wallet and token address.
This endpoint provides the unrealized PnL, average cost, current balance, and current usd balance for given wallet and token addresses. This endpoint is in beta and subject to change.
Important notes and error handling
- This endpoint is currently only supported for solana. The underlying tables are currently being optimized, so data is only available for 2025/01/01 onwards and the endpoint is much slower than usual.
- Value errors are returned for invalid address/token address and unsupported chains.
- If no latest balance is found for a given address/token pair, the endpoint will return that no PnL data has been found.
Supported Chains and Holdings
- Solana
How is PnL calculated?
PnL is calculated using the following formula:
Where:
- Current Balance(Token) = Latest balance of the token for the given address
- Current USD Price(Token) = Latest price of the token in USD
- Average Cost(Token) = Average cost of the token for the given address
Average Cost is based on the average cost basis method calculated by taking a weighted average of all token purchases and reweighting the average cost during sale events.
We’ve also made the following assumptions:
- To prevent false positive such as multiple transfers in intermediate hops of a swap, we only take transfers of tokens with a net change on the tx-level
- The average cost of a token is the price of the token when bought, not the price paid with the other token in a swap. This means slippage/arbitrage is not accounted for
- P2P transfers are not included in the average cost calculation i.e. the token is received for free
- Average cost is “reset” when the token balance decreases. i.e. if you sell some tokens, and your new balance is B, the new average cost will be calculated using
- The pnl calculation shown above is for unrealized gains only. To calculated realized gains, you can do so using the average cost field.
Example
Each row represents a user interaction and what the PnL would be if the user checked the app following the interaction.
Buy/Sell | Token | Amt | Balance | Price | Avg Cost Calculation | PnL |
---|---|---|---|---|---|---|
Buy | SOL | 50 | 50 | $210 | (50 * $210) / (50) | 0 |
Buy | SOL | 10 | 60 | $200 | (50 * 200) / (50 + 10) | -$500 |
Sell | SOL | 10 | 50 | $220 | 50 * avg cost / 50 = 50 * ((50 * 200) / (50 + 10)) / 50 | $583.50 |
Sell | SOL | 2 | 48 | $220 | 48 * avg cost / 48 = 48 * ((50 * 200) / (50 + 10)) / 48 | $560.16 |
User checking app | 48 | $230 | 48 * $208.33 / 48 | $1040.16 | ||
Buy | SOL | 7 | 55 | $180 | 48 * $208.33 + 7 * 180 / 48 + 7 | -$1359.84 |
User checking app | 55 | $185 | 48 * $208.33 + 7 * 180 / 48 + 7 = 204.72 | -$1084.6 |
Authorizations
Body
The body is of type object[]
.
Response
The response is of type object
.