Skip to content

Commit 84b854f

Browse files
author
Louis Tao
committed
Version 0.2.2
1 parent c25ecb6 commit 84b854f

File tree

8 files changed

+102
-86
lines changed

8 files changed

+102
-86
lines changed

assets/images/coverage.svg

Lines changed: 2 additions & 2 deletions
Loading

examples/basic_sub_account.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from hyperliquid.utils import constants
2+
import example_utils
3+
4+
5+
def main():
6+
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
7+
8+
name = "example123"
9+
print(exchange.create_sub_account(name))
10+
11+
sub_accounts = info.query_sub_accounts(address)
12+
for sub_account in sub_accounts:
13+
if sub_account["name"] == name:
14+
sub_account_user = sub_account["subAccountUser"]
15+
16+
print(exchange.sub_account_transfer(sub_account_user, True, 10))
17+
18+
19+
if __name__ == "__main__":
20+
main()

hyperliquid/exchange.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,46 @@ def set_referrer(self, code: str) -> Any:
342342
timestamp,
343343
)
344344

345+
def create_sub_account(self, name: str) -> Any:
346+
timestamp = get_timestamp_ms()
347+
create_sub_account_action = {
348+
"type": "createSubAccount",
349+
"name": name,
350+
}
351+
signature = sign_l1_action(
352+
self.wallet,
353+
create_sub_account_action,
354+
None,
355+
timestamp,
356+
self.base_url == MAINNET_API_URL,
357+
)
358+
return self._post_action(
359+
create_sub_account_action,
360+
signature,
361+
timestamp,
362+
)
363+
364+
def sub_account_transfer(self, sub_account_user: str, is_deposit: bool, usd: int) -> Any:
365+
timestamp = get_timestamp_ms()
366+
sub_account_transfer_action = {
367+
"type": "subAccountTransfer",
368+
"subAccountUser": sub_account_user,
369+
"isDeposit": is_deposit,
370+
"usd": usd,
371+
}
372+
signature = sign_l1_action(
373+
self.wallet,
374+
sub_account_transfer_action,
375+
None,
376+
timestamp,
377+
self.base_url == MAINNET_API_URL,
378+
)
379+
return self._post_action(
380+
sub_account_transfer_action,
381+
signature,
382+
timestamp,
383+
)
384+
345385
def usd_transfer(self, amount: float, destination: str) -> Any:
346386
timestamp = get_timestamp_ms()
347387
payload = {

hyperliquid/info.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ def query_order_by_cloid(self, user: str, cloid: Cloid) -> Any:
281281
def query_referral_state(self, user: str) -> Any:
282282
return self.post("/info", {"type": "referral", "user": user})
283283

284+
def query_sub_accounts(self, user: str) -> Any:
285+
return self.post("/info", {"type": "subAccounts", "user": user})
286+
284287
def subscribe(self, subscription: Subscription, callback: Callable[[Any], None]) -> int:
285288
if self.ws_manager is None:
286289
raise RuntimeError("Cannot call subscribe since skip_ws was used")

0 commit comments

Comments
 (0)