Appendix (Health🏥)
Last updated
Last updated
TurboDEX uses a concept of weighted margin which we refer to as health to determine if an account can be liquidated or open new positions. Health summarizes how risky a user's positions are.
There are two types of health:
Maintenance health - Accounts can be liquidated if the maintenance health drops below 0.
Initial health - A deposit required to initialize a position. Accounts cannot open positions that reduce their initial health to a number below 0.
Each product has four parameters:
maintenance_asset_weight
maintenance_liability_weight
initial_asset_weight
initial_liability_weight
Health is calculated using the corresponding weight number.
A liability (short spot or perp), uses the liability weight, otherwise we use the asset weight (long spot or perp).
We have a two assets, a BTC spot asset, as well as a BTC/USDC-PERP, with:
BTC Spot
maintenance_asset_weight = 0.9
maintenace_liability_weight = 1.1
initial_asset_weight = 0.8
initial_liability_weight = 1.2
BTC/USDC-PERP
maintenance_asset_weight = 0.95
maintenance_liability_weight = 1.05
initial_asset_weight = 0.9
initial_liability_weight = 1.1
These correspond to a 5x initial leverage and 10x maintenance leverage for spot, and a 10x initial leverage and 20x maintenance leverage for perp.
If BTC is currently worth 10k, and a user has 5 BTC spot and is short 10 BTC/USDC-PERP at an average entry price of 9k, then:
The user's spot position contributes 5 * 10,000 * 0.9 == 45,000 to the maintenance health, and 5 * 10,000 * 0.8 == 40,000 to the initial health.
The user's perp position contributes -10 * 10,000 * 0.95 + 90,000 == -5,000 to the maintenance health, and -10 * 10,000 * 0.9 + 90,000 == -10,000 to the initial health. Note that the + 90,000 at the end comes from the average entry price, we can consider it a separate contribution.
This results in a total maintenance health of 45,000 + -5,000 == 40,000 and an initial health of 40,000 + -10,000 == 30,000.
The above works for most accounts, but is not the full picture. An additional risk management measure TurboDEX takes is to reduce leverage for larger accounts to mitigate market impact on liquidation. In practice, this means scaling the above parameters as the position gets larger. Products have an additional parameter large_position_penalty that determines the magnitude of this scaling. In this case:
asset_weight_max = 1.1 / (1 + large_position_penalty * sqrt(quantity_product))
AND
liability_weight_min = 0.9 * (1 + large_position_penalty * sqrt(-quantity_product))
If applicable, we decrease asset weights for the product to asset_weight_max, and increase liability weights to liability_weight_min.