Leveraged trading allows you to trade with more funds than you own. In essence, you are borrowing funds from the exchange. When your position's value reaches a critical point, it will be proactively liquidated to insure against a loss to the exchange.
Perpetual Protocol uses index price to evaluate liquidation conditions.
Maintenance margin: 6.25%
Liquidation is triggered when your position margin ratio is below 6.25%. Margin ratio is calculated using 15-minute TWAP of the index price.
Each position has an associated liquidation price. Note that this price depends on how much collateral you deposited, and the PnL of each position. Depositing, withdrawing, and funding payments all affect your collateral, and therefore affect liquidation price.
The PnL of each position will affect the liquidation price of other positions. If the profit on one position increases, the liquidation price of all positions will decrease (longs) or increase (shorts).
Calculating liquidation price
For accessing the values of various parameters, see Smart contract addresses
#long liqPrice = indexPrice - ((accountValue - totalPositionValue * mmRatio) / ((1 - mmRatio) * positionSizeOfTokenX)) #short liqPrice = indexPrice - ((accountValue - totalPositionValue * mmRatio) / ((1 + mmRatio) * positionSizeOfTokenX))
There is also a helper contract function that returns
Some or all of your margin will be taken as a liquidation penalty.
- If you have a single position: All of your margin will be taken as penalty.
- If you have multiple positions: Margin will be taken from liquidated positions, but only until your account margin is in a healthy state, at which time liquidation will stop. The liquidator can choose which position to liquidate, and will likely choose the biggest position so it can liquidate the maximum allowable amount in the fewest transactions.
Liquidations are performed by keeper bots which anyone can code and run.
These bots call the clearinghouse contract to trigger liquidations, and the clearinghouse determines whether a position meets the conditions for liquidations or not. Liquidators receive a bonus when successfully triggering a liquidation, paid from a portion of the collateral backing the liquidated position.
Please see the following document: