> For the complete documentation index, see [llms.txt](https://docs.sodex.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sodex.com/trading-mechanics/entry-price-and-pnl.md).

# Entry price and PnL

The display of Entry Price and Profit & Loss (PnL) on SoDEX serves as a crucial user-interface layer, while the underlying accounting is anchored in the user's margin balance and trade history.

## Perpetual Contract (Perp) Definitions

<table><thead><tr><th width="139.3125">Trade Type</th><th width="433.69921875">Definition</th><th>Effect on Position Size</th></tr></thead><tbody><tr><td>Opening Trade</td><td>Any trade that increases the absolute size of an existing position (e.g., buying more Long, selling more Short).</td><td>Increases the absolute size.</td></tr><tr><td>Closing Trade</td><td>Any trade that reduces the absolute size of an existing position (e.g., selling a Long position, buying back a Short position).</td><td>Decreases the absolute size.</td></tr></tbody></table>

### **Entry Price Calculation**

* **For Opening Trades:** The Entry Price is **recalculated** using a **weighted average** of the previous entry price and the price of the new trade, based on their respective notional sizes.
* **For Closing Trades:** The Entry Price of the remaining open position **remains unchanged**.

### **PnL Formulas**

#### Unrealized PnL (Open Positions)

This reflects the potential **PnL** of the open position, based on the current **Mark Price**.

$$
\text{Unrealized PnL} = \text{side} \times (\text{mark\_price} - \text{entry\_price}) \times \text{position\_size}
$$

* side = 1 for a **Long** position; side = -1 for a **Short** position.

#### Closed PnL (Realized)

This represents the actual **PnL** realized from a trade:

* **For a Closing Trade:** The **PnL** includes the actual profit/loss from the closed portion, plus fees:

$$
\text{Closed PnL} = \text{fees} + \[\text{side} \times (\text{exit\_price} - \text{entry\_price}) \times \text{closed\_size}]
$$

* **For an Opening Trade:** The **Closed PnL** consists **only of the fees paid** for that trade (as no profit is realized until the position is closed).

<br>

## Spot Market Distinctions

The fundamental **PnL** and Entry Price formulas are applied to the Spot Market with the following accounting conventions:

* **Buys** are treated as **Opening Trades**.
* **Sells** are treated as **Closing Trades**.
* **Wallet transfers** of assets (for accounting purposes) are treated as virtual buys or sells at the **current Mark Price**.
