Margin ratio & Liquidation
The margin ratio is used to assess the risk of a protocol user's position.
Margin ratio calculation:
– user's margin ratio
- total user margin, which includes the amount of uPnL and funding for all positions
– sum of position's collateral
Mt=M+uPnlFaM_{t}=M+\sum{uPnl} - \sum{Fa}
- user's margin
- sum of unrealized PnL
- total funding amount
The following rules are used depending on the value of the margin ratio:
  • If, after the user has made a trade, his
    >= 1, then there is no risk of opening new positions.
  • If 1 <
    < 0.7, then the user cannot open new positions, but he is not subject to liquidation either.
  • If
    < 0.7, a partial liquidation of user positions is possible.
  • A trader cannot withdraw funds from his account if
    < 1 or if, as a result of his withdrawal,
    falls below 1.
  • If
    < 0.4, the complete liquidation of the user's positions is possible.
The commission for closing a position paid to the liquidator is 1.5% of the value of the closed position, and another 1% is sent to the insurance fund. On a separate tab of the interface, a list of users is created, ranked from lowest to highest by margin ratio.

Liquidation terms:

  • If
    < 0.7, the user's position can be liquidated.
  • The
    of the liquidator after liquidation must be > 1.
  • The liquidator is not obliged to “buy back” the entire position of the liquidated person available for closing, the minimum liquidation is 1 contract.
  • The user's position can be liquidated until his
    becomes equal to 0.7, taking into account the penalty charged for liquidation.
Liquidation calculator, which counts how much of a selected asset can be liquidated:
Lp - the maximum possible liquidated position of the user cannot be greater than the user's net position on this asset (for example, if the user has a long of 0.3 BTC, then this amount will be the maximum for liquidation, even if after liquidation his kM will be less than 0.7. However, it is possible if the user has several positions for different assets).
M – liquidated user's margin
uPnL – liquidated user's unrealized PnL
Sm – liquidated user's collateral
Tf – the total liquidation fee in % (2.5%)
Mp – mark price
Fa – funding amount
The result is rounded up to 4 decimals.
If the position is long, then the equation is multiplied by +1, if short, then -1.
The liquidator himself chooses the asset from the open positions of the user, which will be liquidated.
Only 1 asset can be liquidated for the execution of one liquidation contract.
Example: Alice has a long futures position worth 0.3 BTC. The BTC price is 33,330 USDC, the collateral for this position is 1,000 USDC. Alice's margin is 2,100 USDC and uPnL is -1,105 USDC. kM equals to (2,100 + (-1,105)) / 1000 = 0.995. Alice's position cannot be liquidated, but she cannot open new positions either.
The BTC price drops to 31,990 USDC, Alice's uPnL becomes -1507 USDC, collateral equals to 959.7 USDC, and margin remains 2,100 USDC. kM equals to (2,100 + (-1507)) / 959.9 = 0.618.
Bob's margin account is 200 USDC and he wants to liquidate Alice's position. Spin uses the liquidation formula for calculating the maximum available liquidation amount of Alice's BTC:
The number is rounded up to 4 numbers after comma, and final
Bob liquidates 0.0548 BTC of Alice's position and his position is increased to the same value fo Bob's position is: long 0.0548 BTC, his collateral is 175.305 USDC, uPnL is 0 USDC, margin account balance is 226.296 USDC, so kM = 1.291. Bob can close the position or continue holding it.
Alice's position is: long 0.245 BTC, her collateral is 783.76 USDC, uPnL – 1230.72 USDC, margin account balance is 1779.73 USDC and kM = 0.7.
When the position is subject to liquidation, the smart contract checks all the necessary on-chain parameters. Information on the site is displayed off-chain.
The maximum allowable leverage is calculated based on the collateral. If the collateral is 10%, the maximum leverage is x10, because if this value is exceeded, the margin ratio will be insufficient to maintain the position, which may lead to liquidation.
Copy link