From 042ec23b44ac879e98f63e5f1b66d2c86086c236 Mon Sep 17 00:00:00 2001 From: 0xNineteen <0x39015319@gmail.com> Date: Wed, 16 Nov 2022 09:05:05 -0500 Subject: [PATCH] more liq methods --- src/driftpy/clearing_house_user.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/driftpy/clearing_house_user.py b/src/driftpy/clearing_house_user.py index 52294d4d..b9fca8fe 100644 --- a/src/driftpy/clearing_house_user.py +++ b/src/driftpy/clearing_house_user.py @@ -474,6 +474,23 @@ async def get_leverage( return leverage + async def can_be_liquidated( + self, + perp_market_index: int + ) -> bool: + position = await self.get_user_position(perp_market_index) + if position is None or position.base_asset_amount == 0: + return False + + liq_price = await self.get_liq_price(perp_market_index) + perp_market = await self.get_perp_market(perp_market_index) + oracle_price = (await self.get_perp_oracle_data(perp_market)).price / PRICE_PRECISION + + if position.base_asset_amount < 0: + return oracle_price >= liq_price + elif position.base_asset_amount > 0: + return oracle_price <= liq_price + async def get_liq_price( self, perp_market_index: int,