forked from hyperliquid-dex/hyperliquid-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_spot_order.py
More file actions
42 lines (31 loc) · 1.33 KB
/
Copy pathbasic_spot_order.py
File metadata and controls
42 lines (31 loc) · 1.33 KB
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
35
36
37
38
39
40
41
42
import json
from hyperliquid.utils import constants
import example_utils
COIN = "PURR/USDC"
def main():
address, info, exchange = example_utils.setup(base_url=constants.TESTNET_API_URL, skip_ws=True)
# Get the user state and print out position information
spot_user_state = info.spot_user_state(address)
if len(spot_user_state["balances"]) > 0:
print("spot balances:")
for balance in spot_user_state["balances"]:
print(json.dumps(balance, indent=2))
else:
print("no available token balances")
# Place an order that should rest by setting the price very low
order_result = exchange.order(COIN, True, 1200, 0.01, {"limit": {"tif": "Gtc"}})
print(order_result)
# Query the order status by oid
if order_result["status"] == "ok":
status = order_result["response"]["data"]["statuses"][0]
if "resting" in status:
order_status = info.query_order_by_oid(address, status["resting"]["oid"])
print("Order status by oid:", order_status)
# Cancel the order
if order_result["status"] == "ok":
status = order_result["response"]["data"]["statuses"][0]
if "resting" in status:
cancel_result = exchange.cancel(COIN, status["resting"]["oid"])
print(cancel_result)
if __name__ == "__main__":
main()