Liquidation Engine
Last updated
Last updated
It is determined using the following formula:
Only unrealized loss will be considered in this calculation. Any unrealized profit will not be taken into consideration
When Net Collateral <= 0, liquidation will be triggered.
Under a very simplified situation:
User A opened a long position of BTC at 100 today with $10 as collateral with liquidation price showed on UI is 80
Position Fee: $0.09 Borrow Fee: $0.01 Liquidation Fee: $5, or 5% of collateral
User A could get liquidate if:
BTC price is below 80;
BTC price is at 85, but the leverage is high, and the unrealised loss is $20 (which will show on UI), it may cause full/partial liquidation, since collateral ($10) cannot payoff the Loss + Fees ($20+$5+$0.09+$0.01)
Condition A: Full Liquidation
For long positions, when markPrice is less than entryPrice, users will have negative PnL.
When the collateral minus fee and PnL reaches 0, the position will be liquidated.
When the markPrice continues to drop, the negative PnL will increase. When the remainCollateral finally reaches 0, the position will be liquidated. markPrice at that point will be the liquidation price.
The liquidation price can be calculated as:
Condition B: Partial Liquidation
For partial liquidation, fee is not taken into consideration when calculating the remainCollateral.
When the remainCollateral reaches the maxLeverage required collateral, the position will be liquidated.
The liquidation price can be calculated as:
liquidationPrice B will be used when the following condition is met:
Otherwise, liquidationPrice A will be used
For long position:
Liquidation price = Math.max (Liquidation price A or Liquidation price B)
For short position:
Liquidation price = Math.min (Liquidation price A or Liquidation price B)
where
fees = position_fee + liquidation_fee + borrow_fee
position_fee = position_size * 0.1%
liquidation_fee = USD 5
borrowing_fee is calculated based on the borrowing time and borrowing rate.
When the market is fluctuating, the spread of the asset may be high, giving a higher chance of liquidation, meaning liquidation trigger point (spread + market price) could be lower than expected in a short position and vice versa.
There is possibility that your position is not liquidated at the expected specific price due to very sharp price changes.