> ## Documentation Index
> Fetch the complete documentation index at: https://docs.phoenix.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# Entry Price And PnL

> How Phoenix tracks entry price, unrealized PnL, and realized PnL

Phoenix derives entry price from the open position's base size and virtual quote position.

For an open position:

`entry_price = abs(virtual_quote_lot_position) / abs(base_lot_position)`

If `base_lot_position` is zero, the position has no active entry price.

## When entry price changes

Entry price changes when a fill increases exposure.

* if you are flat or long and buy more, Phoenix recalculates the long entry price
* if you are flat or short and sell more, Phoenix recalculates the short entry price
* maker, taker, and spline fills follow the same accounting rules

Reducing a position does not change the remaining entry price. It realizes PnL on the closed portion and preserves the average basis for the open remainder.

A full close removes the entry price. A flip through zero creates a new entry price for the residual position.

## PnL

Unrealized PnL is based on mark price versus entry price:

`unrealized_pnl = position_size * (mark_price - entry_price)`

* long positions gain when mark price rises
* short positions gain when mark price falls

Realized PnL is created when a fill reduces, closes, or flips an existing position.

## What does not change entry price

The following do not change entry price by themselves:

* placing a resting limit order
* funding settlement
* trading fees
* builder fees

Funding and fees affect collateral separately. They are not included in `virtual_quote_lot_position`.

If an opposite-side limit order rests, entry price is unchanged. If it executes, the filled portion follows the normal fill rules above.

## See also

* [Mark Price](/phoenix/margin-and-risk/mark-price)
* [Funding](/phoenix/margin-and-risk/funding-rate)
* [Fees](/phoenix/matching-engine/fees)
