To help users better understand the cause and process of liquidation, we've prepared two sets of examples, one with a single position and the other one with multiple open positions. In both examples, we further list down all possible cases when liquidation is triggered.
General setting:
Alex deposits 1,000 USDC into Symmetry Trade and wants to open positions. The oracle price of BTC is $25,000 and the oracle price of ETH is $2,000 now.
Case 1: Single Open Position
Alex opens +0.2 BTCUSDC position at the execution price of $25,200, Keeperfeemin=$1, UserInputfee=$10, trading fee rate 0.1%. Minimum margin deposit $50.
Scene 1: BTC Oracle price drops from $25,000 to $24,000, Funding = $-20, \sum FinancialCosts = $0.
Now,
Keeper fee is $10.
Alex PnL is 0.2×(24,000−25,200×(1+0.1%))−10=$−255.04.
Margin balance is 1000−255.04−20=$724.96.
Available margin is 724.96−250.2×24,000−50=$482.96.
Buying power is (482.96+50)×25=$13,324.
Maintenance margin is 0.2×24,000×2%=$96.
Maintenance margin ratio is 96724.96=7.55>1.
Scene 2: BTC Oracle price drops from $25,000 to $20,500, $Funding = $50, ∑FinancialCosts=$0.
Now,
Alex PnL is 0.2×(20,500−25,200×(1+0.1%))−10=$−955.04.
Margin balance is 1000−955.04+50=$94.96.
94.96−250.2×20,500−50<0, therefore available margin is 0, trader could not withdraw any money.
Buying power is 0.
Maintenance margin is 0.2×20,500×2%=$82.
Maintenance margin ratio is 8294.96=1.16>1.
Scene 3: BTC Oracle price drops from $25,000 to $20,500, Funding = $30, ∑FinancialCosts=$0.
Now,
Alex PnL is 0.2×(20,500−25,200×(1+0.1%))−10=$−955.04.
Margin balance is 1000−955.04+30=$74.96.
74.96−250.2×20,500−50<0, therefore available margin is 0, trader could not withdraw any money.
Buying power is 0.
Maintenance margin is 0.2 \times 20,500 \times 2\% = \$82.
Maintenance margin ratio is 8274.96=0.91<1.
Out of the three possibilities listed above, Scene 3 would trigger the liquidation process. For the process, we have four different scenarios, categorized by the price at which all BTC/USDC positions are closed:
Then,
Then,
After paying all fees, only $16.55 will be credited to the insurance account, user asset is 0.
Then,
Insurance account pay $3.43 to LP, user asset is 0.
Then,
Then insurance account will pay $43.39 to the keeper bot, LP and protocol, user asset is 0.
Case 2: Multiple Open Positions
Out of the two possibilities listed above, Scene 2 would trigger the liquidation process. For the process, we have two different scenarios, categorized by the price at which all BTC/USDC positions are closed (as BTC/USDC would be the first position to close, ETH/USDC follows):
Then,
No need to further liquidate the ETH/USDC positions now.
Then,
Because the maintenance margin ratio is still below 1, the ETH/USDC position also needs to be liquidated.
All ETH/USDC positions are closed at $2,300. Assume all funding incomes come from BTC/USDC position.
Liquidation keeper fee is 0.2×20,500×0.35%=$14.35<$1000 .
Alex PnL is 0.2×(20,450×(1−0.1%)−25,200×(1+0.1%))−10−14.35=$−983.48.
Margin balance is 1000−983.48+30=$46.52.
Penalty fee is 0.2×20,500×1%=$41.
User asset is 46.52−41=$5.52.$5.52 will be returned to user.
Liquidation keeper fee is 0.2×20,500×0.35%=$14.35<$1000.
Alex PnL is 0.2×(20,300×(1−0.1%)−25,200×(1+0.1%))−10−14.35=$−1013.45.
Margin balance is 1000−1013.45+30=$16.55.
Penalty fee is 0.2×20,500×1%=$41.
Liquidation keeper fee is 0.2×20,500×0.35%=$14.35<$1000.
Alex PnL is 0.2×(20,200×(1−0.1%)−25,200×(1+0.1%))−10−14.35=$−1033.43.
Margin balance is 1000−1033.43+30=$−3.43<0.
Penalty fee is 0.2×20,500×1%=$41.
Liquidation keeper fee is 0.2×20,500×0.35%=$14.35<$1000.
Alex PnL is 0.2×(20,000×(1−0.1%)−25,200×(1+0.1%))−10−14.35=$−1073.39.
Margin balance is 1000−1073.39+30=$−43.39<0.
Alex opens +0.2 BTC/USDC position at the execution price of $25,200 and opens -2 ETH/USDC position at the execution price of $1,990. For each trade, Keeperfeemin=$1, UserInputfee=$10. Trading fee rate 0.1\%. Minimum margin deposit $50.
Scene 1: BTC Oracle price drops from $25,000 to $24,000, and ETH Oracle price drops from $2,000 to $1,900, ∑Funding=$−50, ∑FinancialCosts=$0.
Now,
Scene 2: BTC Oracle price drops from $25,000 to $24,000, and ETH Oracle price increases from $2,000 to $2,300, ∑Funding=$70, ∑FinancialCosts=$0.
Now,
Buying power is 0.
Liquidation keeper fee is 0.2×24,000×0.35%=$16.8<$1000.
Alex PnL is 0.2×(24,000×(1−0.1%)−25,200×(1+0.1%))−2×(2,300−1,990×(1−0.1%))−20−16.8=$−910.62
Penalty fee is 0.2×24,000×1%=$48.
Margin balance is 1000−910.62+70−48=$111.38.
Maintenance margin is 2×2,300×2%=$92.
Maintenance margin ratio is now 92111.38=1.21>1 .
Liquidation keeper fee is 0.2×24,000×0.35%=$16.8<$1000.
Alex PnL is 0.2×(23,500×(1−0.1%)−25,200×(1+0.1%))−2×(2,300−1,990×(1−0.1%))−20−16.8=$−1,010.52
Penalty fee is 0.2×24,000×1%=$48.
Margin balance is 1000−1,010.52+70−48=$11.48.
Maintenance margin is 2×2,300×2%=$92.
Maintenance margin ratio is 9211.48=0.12<1.
After closing BTC/USDC position, USDC deposit is 1000−0.2×(23,500×(1−0.1%)−25,200×(1+0.1%))−10−16.8+70−48=$645.46
Liquidation keeper fee is 2×2,300×0.35%=$16.1<$1000.
Alex PnL is −2×(2,300×(1+0.1%)−1,990×(1−0.1%))−10−16.1=$−654.68.
ETH position penalty fee is 2×2,300×1%=$46.
Margin balance is 645.46−654.68−46=−$55.22<0.
Therefore, insurance account needs to pay ∣645.46−654.68∣=$9.22 to keeper bot, LP & protocol, taker has no asset left.
Alex PnL is 0.2×(24,000−25,200×(1+0.1%))−2×(1,900−1,990×(1−0.1%))−20=$−89.02
Margin balance is 1000−89.02−50=$860.98.
Available margin is 860.98−250.2×24,000+2×1,900−50=$466.98.
Buying power is (466.98+50)×25=$12,924.5.
Maintenance margin is (0.2×24,000+2×1,900)×2%=$172.
Maintenance margin ratio is 172860.98=5.0>1
Alex PnL is 0.2×(24,000−25,200×(1+0.1%))−2×(2,300−1,990×(1−0.1%))−20=$−889.02
Margin balance is 1000−889.02+70=$180.98.
180.98−250.2×24,000+2×2,300−50<0, therefore available margin is 0, trader could not withdraw any money.
Maintenance margin is (0.2×24,000+2,300×2)×2%=$188.