Skip to content

Commit

Permalink
Handle subaccount for usd_class_transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
traderben committed Oct 2, 2024
1 parent 7eaf6f5 commit 3d3840c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/basic_spot_to_perp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def main():
address, info, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)

# Transfer 1.23 USDC from perp wallet to spot wallet
transfer_result = exchange.user_spot_transfer(1.23, False)
transfer_result = exchange.usd_class_transfer(1.23, False)
print(transfer_result)

# Transfer 1.23 USDC from spot wallet to perp wallet
transfer_result = exchange.user_spot_transfer(1.23, True)
transfer_result = exchange.usd_class_transfer(1.23, True)
print(transfer_result)


Expand Down
8 changes: 6 additions & 2 deletions hyperliquid/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _post_action(self, action, signature, nonce):
"action": action,
"nonce": nonce,
"signature": signature,
"vaultAddress": self.vault_address,
"vaultAddress": self.vault_address if action["type"] != "usdClassTransfer" else None,
}
logging.debug(payload)
return self.post("/exchange", payload)
Expand Down Expand Up @@ -402,9 +402,13 @@ def create_sub_account(self, name: str) -> Any:

def usd_class_transfer(self, amount: float, to_perp: bool) -> Any:
timestamp = get_timestamp_ms()
str_amount = str(amount)
if self.vault_address:
str_amount += f" subaccount:{self.vault_address}"

action = {
"type": "usdClassTransfer",
"amount": str(amount),
"amount": str_amount,
"toPerp": to_perp,
"nonce": timestamp,
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "hyperliquid-python-sdk"
version = "0.7.0"
version = "0.7.1"
description = "SDK for Hyperliquid API trading with Python."
readme = "README.md"
authors = ["Hyperliquid <[email protected]>"]
Expand Down

0 comments on commit 3d3840c

Please sign in to comment.