Skip to content

Commit 3d3840c

Browse files
committed
Handle subaccount for usd_class_transfer
1 parent 7eaf6f5 commit 3d3840c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

examples/basic_spot_to_perp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def main():
66
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)
77

88
# Transfer 1.23 USDC from perp wallet to spot wallet
9-
transfer_result = exchange.user_spot_transfer(1.23, False)
9+
transfer_result = exchange.usd_class_transfer(1.23, False)
1010
print(transfer_result)
1111

1212
# Transfer 1.23 USDC from spot wallet to perp wallet
13-
transfer_result = exchange.user_spot_transfer(1.23, True)
13+
transfer_result = exchange.usd_class_transfer(1.23, True)
1414
print(transfer_result)
1515

1616

hyperliquid/exchange.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _post_action(self, action, signature, nonce):
5555
"action": action,
5656
"nonce": nonce,
5757
"signature": signature,
58-
"vaultAddress": self.vault_address,
58+
"vaultAddress": self.vault_address if action["type"] != "usdClassTransfer" else None,
5959
}
6060
logging.debug(payload)
6161
return self.post("/exchange", payload)
@@ -402,9 +402,13 @@ def create_sub_account(self, name: str) -> Any:
402402

403403
def usd_class_transfer(self, amount: float, to_perp: bool) -> Any:
404404
timestamp = get_timestamp_ms()
405+
str_amount = str(amount)
406+
if self.vault_address:
407+
str_amount += f" subaccount:{self.vault_address}"
408+
405409
action = {
406410
"type": "usdClassTransfer",
407-
"amount": str(amount),
411+
"amount": str_amount,
408412
"toPerp": to_perp,
409413
"nonce": timestamp,
410414
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
55

66
[tool.poetry]
77
name = "hyperliquid-python-sdk"
8-
version = "0.7.0"
8+
version = "0.7.1"
99
description = "SDK for Hyperliquid API trading with Python."
1010
readme = "README.md"
1111
authors = ["Hyperliquid <[email protected]>"]

0 commit comments

Comments
 (0)