dydx-v3-python icon indicating copy to clipboard operation
dydx-v3-python copied to clipboard

liquidation price formula

Open saleh-mir opened this issue 2 years ago • 2 comments

Hi there,

I have been following the formula on the documentation but my numbers are always about 3 percent off. is there any example code that I can look into?

this is my code:

maintenance_margin_fraction = float(self.vars['market_info'][symbol]['maintenanceMarginFraction'])
oracle_price = float(self.client.public.get_markets(symbol).data['markets'][symbol]['oraclePrice'])

is_long = position_type == 'long'
is_short = position_type == 'short'
is_close = position_type == 'close'

try:
    total_account_value = self.vars['quote_balance']
except KeyError:
    self.fetch_account_balance()
    total_account_value = self.vars['quote_balance']
total_maintenance_margin_requirement = 0
for s in self.exchange_trading_symbols:

    total_maintenance_margin_requirement += abs(
        qty * oracle_price * float(self.vars['market_info'][symbol]['maintenanceMarginFraction'])
    )
    total_account_value += abs(qty * oracle_price)
if is_long:
    return oracle_price * (
                1 - (maintenance_margin_fraction * total_account_value / total_maintenance_margin_requirement))
elif is_short:
    return oracle_price * (
                1 + (maintenance_margin_fraction * total_account_value / total_maintenance_margin_requirement))
else:
    return None

saleh-mir avatar Feb 28 '23 15:02 saleh-mir

  • Did you find a solution ?.

traderblakeq avatar Apr 12 '23 10:04 traderblakeq

  • Did you find a solution ?.

Unfortunatly no.

saleh-mir avatar May 05 '23 11:05 saleh-mir