Philosophy
Your app likely its own high-performance system for live prices. (If not, we can recommend pricing APIs for you.) For that reason, the Clicker API only returns historical data: cost basis, realized PnL, and position amounts. You bring your own live price data to these calculations. These fields can be found inmetadata and metadata.positionStats of a HydratedPosition.
Detecting Spot vs Perps
Checkmetadata.perpPositionType. If it’s "long" or "short", the position is a perp. If it’s null or absent, it’s spot.
For Hyperliquid positions, you can also check for the presence of positionAmountWithLeverage.
Spot Positions
Current Value
| Field | Source |
|---|---|
positionAmount | metadata.positionAmount |
currentPrice | Your pricing feed |
Unrealized PnL
| Field | Source |
|---|---|
holdingsCostBasisUSD | metadata.positionStats.holdingsCostBasisUSD |
holdingReceivedCostBasisUSD | metadata.positionStats.holdingReceivedCostBasisUSD |
holdingsCostBasisUSD is the cost basis of tokens the trader bought. holdingReceivedCostBasisUSD is the cost basis of tokens the trader received via airdrops or transfers, valued at market price at the time of receipt. Together they form the full cost basis of current holdings.
Total PnL
To show total PnL (realized + unrealized):realizedGainsUSD captures profit or loss from tokens already sold.
Percent Change
| Field | Source |
|---|---|
boughtUSD | metadata.positionStats.boughtUSD |
receivedCostBasisUSD | metadata.positionStats.receivedCostBasisUSD |
totalInvested >= 1. Below that threshold, the percentage is meaningless.
Example
A trader bought 10,000 tokens at $0.05 for $500. The token is now $0.08.Perp Positions
Perps use leveraged values for PnL and margin (collateral) for position value.Unrealized PnL
Compute the current leveraged notional value:| Field | Source |
|---|---|
positionAmountWithLeverage | metadata.positionAmountWithLeverage |
holdingsCostBasisUSDWithLeverage | metadata.positionStats.holdingsCostBasisUSDWithLeverage |
Current Value (Equity)
For perps, the position value is the trader’s equity: margin plus unrealized PnL.holdingsCostBasisUSD on a perp position represents the margin (collateral) posted, not the full notional exposure.
Total PnL
Percent Change
boughtUSD on a perp is the total margin posted across all entries.
Example
A trader opens a 5x long on ETH at $3,000 with $1,000 margin. ETH is now $3,300.Closed Positions
A position is closed when the trader has exited entirely. For closed positions, there is no unrealized PnL to compute. DisplayrealizedGainsUSD as the total PnL and compute percent change against totalInvested as above.
metadata.positionStats.isOpen === false, or by checking that positionAmount is near zero (below 0.0001).