-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathbasic_leverage_adjustment.py
34 lines (23 loc) · 1.19 KB
/
basic_leverage_adjustment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import json
import example_utils
from hyperliquid.utils import constants
def main():
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
# Get the user state and print out leverage information for ETH
user_state = info.user_state(address)
for asset_position in user_state["assetPositions"]:
if asset_position["position"]["coin"] == "ETH":
print("Current leverage for ETH:", json.dumps(asset_position["position"]["leverage"], indent=2))
# Set the ETH leverage to 21x (cross margin)
print(exchange.update_leverage(21, "ETH"))
# Set the ETH leverage to 22x (isolated margin)
print(exchange.update_leverage(21, "ETH", False))
# Add 1 dollar of extra margin to the ETH position
print(exchange.update_isolated_margin(1, "ETH"))
# Get the user state and print out the final leverage information after our changes
user_state = info.user_state(address)
for asset_position in user_state["assetPositions"]:
if asset_position["position"]["coin"] == "ETH":
print("Current leverage for ETH:", json.dumps(asset_position["position"]["leverage"], indent=2))
if __name__ == "__main__":
main()