Skip to content

Commit

Permalink
more liq methods
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNineteen committed Nov 16, 2022
1 parent 9afad4b commit 042ec23
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/driftpy/clearing_house_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 042ec23

Please sign in to comment.