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

# Entry Price / PnL

<figure><img src="/files/zTJlTt1ozmm8k8cgJgS9" alt=""><figcaption></figcaption></figure>

#### Entry Price / PnL

Entry price, unrealized PnL, and closed PnL are client-side calculations meant for user clarity — they are not part of the protocol’s on-chain accounting, which is instead based solely on margin (for perps) or balances (for spot) and executed trades.

***

### Perpetual Markets

* A trade is considered opening if it increases the absolute size of your position — e.g., going longer while already long, or adding to a short.
* A closing trade reduces your position size in the opposite direction.

**Entry Price Logic:**

* For opening trades, the entry price is recalculated using a size-weighted average of the current entry price and the new trade price.
* For closing trades, the entry price remains unchanged.

{% code overflow="wrap" %}

```
Unrealized PnL = side × (mark_price − entry_price) × position_size 
```

{% endcode %}

{% code overflow="wrap" %}

```
Closed PnL = side × (exit_price − entry_price) × position_size + fees.
```

{% endcode %}

### Spot Markets

Spot PnL calculations follow similar logic to perps with a few key differences:

* Buys are treated as opening trades, and sells as closing trades.
* Transfers are treated as buys or sells at the current mark price.

\*UBTC on Hyperliquid always matches the BTC held in custody, maintaining a 1:1 peg.
