What is PnL?
PnL stands for Profit and Loss, which reflects how much you’ve gained or lost on your open position. It’s a critical metric to track as it shows how well your trade is performing based on price movements.
How PnL Works
When you open a position on Jupiter Perps (long or short), your PnL updates in real-time as the market moves. The PnLvalue can either be positive (profit) or negative (loss), depending on whether the price is moving in your favor or against you.
For long positions, if the price of your asset goes up, your PnL increases. If the price drops, your PnL decreases. For example:
- Position: 1,000 USD long on SOL
- If SOL price increases by 10%: You profit 100 USD
- If SOL price decreases by 10%: You lose 100 USD
For short positions, the opposite happens. If the price of the asset goes down, your PnL increases. If the price rises, your PnL decreases. For example:
- Position: 1,000 USD short on SOL
- If SOL price decreases by 10%: You profit 100 USD
- If SOL price increases by 10%: You lose 100 USD
Understanding PnL Calls
A PnL Call occurs when the value of your open position reaches a certain threshold, triggering a call for additional collateral to maintain the position.
If your PnL turns negative and your margin falls below the maintenance level, you may be required to deposit more collateral to avoid liquidation.
Calculating realized and unrealized PnL
// 1) Get the current token price / exit price
exitPrice = currentTokenPrice
// 2) Determine if the position is profitable by checking if the exit price is greater than the position's
// average price for longs, or if the exit price is less than the position's average price for shorts
IF isLong THEN
inProfit = exitPrice > positionAvgPrice
ELSE
inProfit = exitPrice < positionAvgPrice
// 3) Calculate the absolute delta between the exit price and the position's average price
priceDelta = |exitPrice - positionAvgPrice|
// 4) Calculate the PnL delta for the closed portion of the position: multiply the size being closed (`tradeSizeUsd`)
// by the price delta, then divide by the entry price to get the PnL delta
pnlDelta = (tradeSizeUsd * priceDelta) / positionAvgPrice
// 5) Calculate the final unrealized PnL depending on whether the position is profitable or not
IF inProfit THEN
unrealizedPnl = pnlDelta
ELSE
unrealizedPnl = -pnlDelta
// 6) Deduct the outstanding fees from the unrealized PnL to get the final realized PnL
// Read the `Fee` section below to understand how the fee calculations work
realizedPnl = unrealizedPnl - (closeBaseFee + priceImpactFee + borrowFee)
By understanding and monitoring your PnL, you can make informed decisions on whether to adjust your position, take profits, or cut losses, giving you more control over your trades.