Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liquidation price formula #199

Open
saleh-mir opened this issue Feb 28, 2023 · 2 comments
Open

liquidation price formula #199

saleh-mir opened this issue Feb 28, 2023 · 2 comments

Comments

@saleh-mir
Copy link

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
Copy link

  • Did you find a solution ?.

@saleh-mir
Copy link
Author

  • Did you find a solution ?.

Unfortunatly no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants