Skip to content

Commit 65f0426

Browse files
committed
fix: fix liquidation price calculation in the liquidable positions example script
1 parent 95f9b21 commit 65f0426

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/chain_client/10_SearchLiquidablePositions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ async def main() -> None:
4242
market_cumulative_funding = client_market._from_extended_chain_format(Decimal(market["perpetualInfo"]["fundingInfo"]["cumulativeFunding"]))
4343

4444
adj_margin = adjusted_margin(quantity, margin, is_long, cumulative_funding_entry, market_cumulative_funding)
45-
adjusted_unit_margin = (adj_margin / quantity) * (1 if is_long else -1)
46-
45+
adjusted_unit_margin = (adj_margin / quantity) * (-1 if is_long else 1)
4746
maintenance_margin_ratio = client_market.maintenance_margin_ratio * (-1 if is_long else 1)
47+
4848
liquidation_price = (entry_price + adjusted_unit_margin) / (Decimal(1) + maintenance_margin_ratio)
4949

5050
should_be_liquidated = (is_long and market_mark_price <= liquidation_price) or (not is_long and market_mark_price >= liquidation_price)
5151

5252
if should_be_liquidated:
53+
print(f"Test {(Decimal(1) + maintenance_margin_ratio)} || market mantainance margin ratio: {client_market.maintenance_margin_ratio}")
5354
print(f"{'Long' if is_long else 'Short'} position for market {client_market.id} and subaccount {position['subaccountId']} should be liquidated (liquidation price: {liquidation_price.normalize()} / mark price: {market_mark_price.normalize()})")
5455
liquidable_positions.append(position)
5556

0 commit comments

Comments
 (0)