There are two values to manage the state of your account:
- Required Maintanance Margin: The minimum margin required to avoid liquidation. If account value < required maintance margin, then your account will be liquidated.
Free Collateral: The collateral available for withdrawal and/or opening new positions. As your PnL increases, so will your free collateral. Rage trade enables you to withdraw your unrealized PnL from your free collateral (as long as your account value > required initial margin).
Traders can calculate their required margin using their token position, current price, and maintanance margin fraction (MMF).
Maintanance Margin Fraction (MMF) = 1/10
Required Margin (Trader) = Token Position x Current Price x MMF.
NOTE: This section is not intended for LPs in 80-20 vaults. LP margin calculation is more involved than trader margin calculation. For this reason, we recommend using 80-20 vaults to provide liquidity without worrying about margin or liquidation risk (read about 80-20 here).
Let's use the visualization of the range order below to understand LP margin calculation:
In the above diagram an LP has provided a range order with vUSD and vETH around the current price. To calculate the LPs required margin, let's analyze the downside risk (price going down) and upside risk (price going up) of the LP.
Upside Risk: As price moves up, the LP sells vETH for vUSD (i.e. the LP shorts ETH). To calculate the worst-case risk of the LP we use (1) maximum ETH short position and (2) current perp price.
Up Risk = Maximum Short Position * Current Price
Downside Risk: As price moves down, the LP buys vETH with vUSD (i.e. the LP longs ETH). To calculate the worst-case risk of the LP we use (1) maximum vETH long position and (2) execution price bounded by high/low range price.
Execution Price = SQRT(MIN(Low Price, Current Price) * MIN(Current Price, High Price))
Down Risk = Maximum Long Position * Execution Price
Knowing the upside risk and downside risk of a range, we can take the maximum to calculate the required margin:
Required Margin (LP) = MAX(Up Risk, Down Risk) * MMF
For users that are both providing liquidity and trading, we can sum the risks to calculate the required margin:
Trade Risk = Token Position * Current Price
Required Margin = MAX(Up Risk + Trade Risk, Down Risk + Trade Risk) * MMF