Account value is essential for calculating margin ratio and free collateral.

This value is the sum of your collateral, any unrealized PnL (profit & loss) and any settled or pending fees and funding payments associated with your open positions:

\begin{aligned} accountValue &= \underbrace{collateral + owedRealizedPnl + pendingFundingPayment + pendingFee}_{totalCollateralValue} + \underbrace{\sum_{market}{unrealizedPnl_{market}}}_{totalUnrealizedPnl} \end{aligned}

## Free Collateral

Free collateral is funds you have available for using as margin, i.e., opening positions. It is also used in determining how much you can withdraw from the exchange at any given time.

\begin{aligned} freeCollateral(ratio) &= min(totalCollateralValue, accountValue) - openOrderMarginReq(ratio) \\\\ freeCollateral_{withdrawal} &:= \text{amount of collateral available for withdrawal or opening new positions/orders} \\ &= freeCollateral(imRatio) \\ imRatio &:= \text{initial margin requirement ratio} \\\\ freeCollateral_{cancelOrder} &:= \text{negative means excess orders and can be cancelled} \\ &= freeCollateral(mmRatio) \\ mmRatio &:= \text{maintenance margin ratio (account will be liquidated if its margin ratio falls below)} \end{aligned}

## Buying Power

Buying power (BP) is the amount of funds you have available for opening positions. This includes all available leverage (up to 10x). Therefore, if you use 100% of your BP to open a new position, your account leverage will be 10x. The maximum percent BP and resulting leverage will vary slightly in practice so you may not be able to use 100% of BP or attain 10x leverage directly via the UI.

Assuming you have no open positions, the buying power can be estimated as follows.

\[buyingPower=10(freeCollateral)\]

This also holds if you have an open position and you are opening a new position in the same direction (e.g. you have an ETH long and you are opening a new ETH long.)

However, when you want to open a position in the direction opposite to an existing position, the buying power needs to cover the existing position. This can be **approximated** as follows.

\[buyingPower=2(existingPositionValue)+10(freeCollateral)\]

### Moving Beyond Approximations

The actual underlying math is more complex. The following is a high level explanation.

Assuming `increasePosition`

:

\begin{aligned} buyingPower_{market,increasePosition} &= \frac{freeCollateral_{withdrawal}}{imRatio} \\ imRatio &:= \text{initial margin requirement ratio} \end{aligned}

Assuming `reducePosition`

:

\begin{aligned} buyingPower_{market,reversePosition} &= |positionValue_{market}| + buyingPower_{market,closed} \\ buyingPower_{market,closed} &:= \text{estimated buying power after the current position is closed}\\ \end{aligned}