forked from hyperliquid-dex/hyperliquid-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_sub_account.py
More file actions
26 lines (18 loc) · 1014 Bytes
/
basic_sub_account.py
File metadata and controls
26 lines (18 loc) · 1014 Bytes
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
import example_utils
from hyperliquid.utils import constants
# This example shows how to create, query, and transfer funds to a subaccount.
# To trade as a subaccount set vault_address to the subaccount's address. See basic_vault.py for an example.
def main():
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
name = "example123"
print(exchange.create_sub_account(name))
sub_accounts = info.query_sub_accounts(address)
for sub_account in sub_accounts:
if sub_account["name"] == name:
sub_account_user = sub_account["subAccountUser"]
# Transfer 1 USD to the subaccount
print(exchange.sub_account_transfer(sub_account_user, True, 1_000_000))
# Transfer 1.23 HYPE to the subaccount (the token string assumes testnet, the address needs to be changed for mainnet)
print(exchange.sub_account_spot_transfer(sub_account_user, True, "HYPE:0x7317beb7cceed72ef0b346074cc8e7ab", 1.23))
if __name__ == "__main__":
main()