Skip to content

Commit 1c7fb55

Browse files
committed
fix: solved pre-commit issues
1 parent 987e82b commit 1c7fb55

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

examples/chain_client/10_SearchLiquidablePositions.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
from pyinjective.async_client_v2 import AsyncClient
55
from pyinjective.core.network import Network
66

7-
def adjusted_margin(quantity: Decimal, margin: Decimal, is_long: bool, cumulative_funding_entry: Decimal, cumulative_funding: Decimal) -> Decimal:
7+
8+
def adjusted_margin(
9+
quantity: Decimal, margin: Decimal, is_long: bool, cumulative_funding_entry: Decimal, cumulative_funding: Decimal
10+
) -> Decimal:
811
unrealized_funding_payment = (cumulative_funding - cumulative_funding_entry) * quantity * (-1 if is_long else 1)
912
return margin + unrealized_funding_payment
1013

14+
1115
async def main() -> None:
1216
# select network: local, testnet, mainnet
1317
network = Network.mainnet()
@@ -38,23 +42,35 @@ async def main() -> None:
3842
quantity = client_market._from_extended_chain_format(Decimal(position["position"]["quantity"]))
3943
entry_price = client_market._from_extended_chain_format(Decimal(position["position"]["entryPrice"]))
4044
margin = client_market._from_extended_chain_format(Decimal(position["position"]["margin"]))
41-
cumulative_funding_entry = client_market._from_extended_chain_format(Decimal(position["position"]["cumulativeFundingEntry"]))
42-
market_cumulative_funding = client_market._from_extended_chain_format(Decimal(market["perpetualInfo"]["fundingInfo"]["cumulativeFunding"]))
45+
cumulative_funding_entry = client_market._from_extended_chain_format(
46+
Decimal(position["position"]["cumulativeFundingEntry"])
47+
)
48+
market_cumulative_funding = client_market._from_extended_chain_format(
49+
Decimal(market["perpetualInfo"]["fundingInfo"]["cumulativeFunding"])
50+
)
4351

4452
adj_margin = adjusted_margin(quantity, margin, is_long, cumulative_funding_entry, market_cumulative_funding)
4553
adjusted_unit_margin = (adj_margin / quantity) * (-1 if is_long else 1)
4654
maintenance_margin_ratio = client_market.maintenance_margin_ratio * (-1 if is_long else 1)
4755

4856
liquidation_price = (entry_price + adjusted_unit_margin) / (Decimal(1) + maintenance_margin_ratio)
4957

50-
should_be_liquidated = (is_long and market_mark_price <= liquidation_price) or (not is_long and market_mark_price >= liquidation_price)
58+
should_be_liquidated = (is_long and market_mark_price <= liquidation_price) or (
59+
not is_long and market_mark_price >= liquidation_price
60+
)
5161

5262
if should_be_liquidated:
53-
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()})")
63+
position_side = "Long" if is_long else "Short"
64+
print(
65+
f"{position_side} position for market {client_market.id} and subaccount "
66+
f"{position['subaccountId']} should be liquidated (liquidation price: "
67+
f"{liquidation_price.normalize()} / mark price: {market_mark_price.normalize()})"
68+
)
5469
liquidable_positions.append(position)
5570

5671
# print(f"\n\n\n")
5772
# print(json.dumps(liquidable_positions, indent=4))
5873

74+
5975
if __name__ == "__main__":
6076
asyncio.get_event_loop().run_until_complete(main())

0 commit comments

Comments
 (0)