Skip to content

Calculate unrealized G/L with auto-fetched prices

GET
/api/calculate/unrealized-gl/{address}
curl --request GET \
--url https://api.qeychain.xyz/api/calculate/unrealized-gl/example

Calculates unrealized gain/loss for all open lots with AUTOMATIC price fetching.

This endpoint:
1. Fetches all transactions from Zerion
2. Enriches historical prices from CoinGecko (for missing Zerion prices)
3. Fetches current prices from CoinGecko
4. Calculates unrealized G/L for all open positions

No need to manually provide current_prices - they are fetched automatically.

Note: This endpoint may be slower due to CoinGecko rate limits. For high-frequency
use, consider caching the prices or using the POST /unrealized-gl endpoint
with pre-fetched prices.
address
required
Address
string
owned_wallets
Any of:
Array<string>

All wallet addresses owned by the user (for internal transfer detection)

Successful Response

Media typeapplication/json
UnrealizedGLResponse

Portfolio-level unrealized gain/loss response.

object
by_asset
By Asset

Unrealized G/L by asset (keyed by token_key)

object
key
additional properties
AssetUnrealizedGLResponse

Unrealized G/L aggregated by asset.

object
symbol
required
Symbol

Token symbol

string
chain
required
Chain

Blockchain network

string
quantity
required
Quantity

Total quantity held

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
current_price
required
Current Price

Current market price

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
cost_basis
required
Cost Basis

Total cost basis

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
current_value
required
Current Value

Current market value

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
unrealized_gl
required
Unrealized Gl

Unrealized gain/loss

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
unrealized_gl_percent
required
Unrealized Gl Percent

Unrealized G/L as percentage

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
lots
Lots

Per-lot breakdown

Array<object>
LotUnrealizedGLResponse

Unrealized G/L for a single lot.

object
lot_id
required
Lot Id

Lot identifier

string
remaining_quantity
required
Remaining Quantity

Remaining quantity in lot

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
cost_per_unit
required
Cost Per Unit

Cost basis per unit

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
current_price
required
Current Price

Current market price

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
cost_basis
required
Cost Basis

Total cost basis (remaining)

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
current_value
required
Current Value

Current market value

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
unrealized_gl
required
Unrealized Gl

Unrealized gain/loss

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
acquisition_date
Any of:
string format: date-time
is_untracked
Is Untracked

Whether lot has unknown cost basis

boolean
portfolio_total
required
Portfolio Total

Total unrealized G/L across all assets

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
portfolio_unrealized_gain
required
Portfolio Unrealized Gain

Sum of positive unrealized G/L

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
portfolio_unrealized_loss
required
Portfolio Unrealized Loss

Sum of negative unrealized G/L (as positive number)

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
total_cost_basis
required
Total Cost Basis

Total cost basis of open positions

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
total_current_value
required
Total Current Value

Total current market value of open positions

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
portfolio_unrealized_gl_percent
required
Portfolio Unrealized Gl Percent

Portfolio unrealized G/L as percentage of cost basis

string
/^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$/
Example
{
"by_asset": {
"additionalProperty": {
"lots": [
{
"is_untracked": false
}
]
}
}
}

Bad Request

Media typeapplication/json
ErrorResponse

Standard error response.

object
detail
required
Detail

Error message

string
error_code
Any of:
string
Examplegenerated
{
"detail": "example",
"error_code": "example"
}

Not Found

Media typeapplication/json
ErrorResponse

Standard error response.

object
detail
required
Detail

Error message

string
error_code
Any of:
string
Examplegenerated
{
"detail": "example",
"error_code": "example"
}

Validation Error

Media typeapplication/json
HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
Examplegenerated
{
"detail": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
]
}

Internal Server Error

Media typeapplication/json
ErrorResponse

Standard error response.

object
detail
required
Detail

Error message

string
error_code
Any of:
string
Examplegenerated
{
"detail": "example",
"error_code": "example"
}