POST
/
api
/
v1
/
developer
/
wallet
/
pnl-by-token
Get Pnl By Token
curl --request POST \
  --url https://api.allium.so/api/v1/developer/wallet/pnl-by-token \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <api-key>' \
  --data '[
  "<any>"
]'
"<any>"
This endpoint provides the unrealized PnL, realized PnL, average cost, current balance, and current USD balance for given wallet and token addresses. Important notes and error handling
  • This endpoint is currently only supported for Bitcoin and Ethereum.
  • Invalid data (such as unsupported chains or invalid address/token address) returns status code 400.
Supported Chains and Holdings How is PnL calculated? PnL is calculated using the following formula: PnL=Current Balance(Token)×(Current USD Price(Token)Average Cost(Token))\text{PnL} = \text{Current Balance(Token)} \times \left( \text{Current USD Price(Token)} - \text{Average Cost(Token)} \right) 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. Here are more details about our methodology:
  • PnL calculation is based on token balances
  • Realized PnL is calculated by multiplying the number of tokens sold with the difference between sold price and average price
  • Unrealized PnL is calcualted by multiplying the number of tokens held with the difference between current price and average price
Example Each row represents a user interaction and what the PnL would be if the user checked the app following the interaction.
Buy/SellTokenAmtBalancePriceAvg Cost CalculationPnL
BuySOL5050$210(50 * $210) / (50)0
BuySOL1060$200(50 * 210)+(10210) + (10 * 200) / (50 + 10)-$500
SellSOL1050$22050 * avg cost / 50 = 50 * ((50 * 210)+(10210) + (10 * 200) / (50 + 10)) / 50$583.50
SellSOL248$22048 * avg cost / 48 = 48 * ((50 * 210)+(10210) + (10 * 200) / (50 + 10)) / 48$560.16
User checking app48$23048 * $208.33 / 48$1040.16
BuySOL755$18048 * $208.33 + 7 * 180 / 48 + 7-$1359.84
User checking app55$18548 * $208.33 + 7 * 180 / 48 + 7 = 204.72-$1084.6

Authorizations

X-API-KEY
string
header
required

Body

application/json · any[]

The body is of type any[].

Response

200
application/json

Successful Response

The response is of type any.