Calculate unrealized gain/loss for open positions
const url = 'https://api.qeychain.xyz/api/calculate/unrealized-gl';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"current_prices":{"additionalProperty":1},"transactions":[{}],"address":"example","owned_wallets":["example"]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.qeychain.xyz/api/calculate/unrealized-gl \ --header 'Content-Type: application/json' \ --data '{ "current_prices": { "additionalProperty": 1 }, "transactions": [ {} ], "address": "example", "owned_wallets": [ "example" ] }'Calculates unrealized gain/loss for all open lots based on provided current prices.
For each open lot: unrealized_gl = (current_price - cost_per_unit) * remaining_quantity
Aggregates by:
- Individual lot level
- Asset level (per token)
- Portfolio level (total)
Requires either:
- `transactions`: Pre-fetched transactions to process, OR
- `address`: Wallet address to fetch transactions from Zerion
Plus `current_prices`: Dict mapping token_key (chain:symbol) or symbol to current USD price.
Request Bodyrequired
Section titled “Request Bodyrequired”Request for unrealized gain/loss calculation.
object
object
Examplegenerated
{ "current_prices": { "additionalProperty": 1 }, "transactions": [ {} ], "address": "example", "owned_wallets": [ "example" ]}Responses
Section titled “Responses”Successful Response
Portfolio-level unrealized gain/loss response.
object
Unrealized G/L by asset (keyed by token_key)
object
Unrealized G/L aggregated by asset.
object
Token symbol
Blockchain network
Total quantity held
Current market price
Total cost basis
Current market value
Unrealized gain/loss
Unrealized G/L as percentage
Per-lot breakdown
Unrealized G/L for a single lot.
object
Lot identifier
Remaining quantity in lot
Cost basis per unit
Current market price
Total cost basis (remaining)
Current market value
Unrealized gain/loss
Whether lot has unknown cost basis
Total unrealized G/L across all assets
Sum of positive unrealized G/L
Sum of negative unrealized G/L (as positive number)
Total cost basis of open positions
Total current market value of open positions
Portfolio unrealized G/L as percentage of cost basis
Example
{ "by_asset": { "additionalProperty": { "lots": [ { "is_untracked": false } ] } }}Bad Request
Not Found
Validation Error
object
object
Examplegenerated
{ "detail": [ { "loc": [ "example" ], "msg": "example", "type": "example" } ]}Internal Server Error
