# PnL And Total Account Value

### **Perps Trading**

***Unrealized PnL*** shows how much you would gain or lose if you closed your positions at the current [mark price](/trading/fair-price-marking.md).

Let  $$pos\_i$$ be the current position size of an account. $$pos\_i$$ is positive if the account position is long and negative if it is short. The unrealized PnL of the account can be calculated as:

$$
\text{Unrealized PnL} := \sum(\text{markPrice}\_i - \text{avgEntryPrice}\_i) \times position\_i
$$

**Realized PnL** is the gain / loss that has already been captured from the position after closing or due to funding payments. It is calculated based on the difference in USDC value between your average entry price and exit price. Additionally, all funding payments for the position are immediately applied to its realized PNL.

* When the user is closing a portion of an existing long or short position, average entry price stays the same and exchange realizes the difference in average exit and entry prices.

$$
\Delta Collateral := (\text{exitPrice}\_i - \text{avgEntryPrice}\_i) \times \Delta position\_i
$$

* When the user is increasing the size of their open position, no PnL is realized. Exchange updates the average entry price according to the following formula

$$
\text{avgEntryPrice}*{i, new} :=  \frac{{avgEntryPrice}*{i, old }\times {position\_{i, old}} + {tradePrice\times tradeSize}}{position\_{i, new}}
$$

### **Spot Trading**

### Total Account Value

***Total Account Value*** represents the total USDC value of an account in Lighter, including all open positions and collateral. It is calculated as follows:

$$
\text{Total Account Value} = \text{Collateral} + \text{Unrealized PnL}
$$

Note: Isolated positions use a separate collateral balance (Allocated Margin) dedicated solely to that specific position. It functions the same as collateral but applies only to the relevant position and should be treated as collateral in the calculations above.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lighter.xyz/trading/pnl-and-total-account-value.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
