liquidation price formula
saleh-mir opened this issue · 2 comments
saleh-mir commented
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
traderblakeq commented
- Did you find a solution ?.
saleh-mir commented
- Did you find a solution ?.
Unfortunatly no.