2626 sign_withdraw_from_bridge_action ,
2727 sign_agent ,
2828)
29- from hyperliquid .utils .types import Any , List , Meta , Optional , Tuple , Cloid
29+ from hyperliquid .utils .types import Any , List , Meta , SpotMeta , Optional , Tuple , Cloid
3030
3131
3232class Exchange (API ):
@@ -41,6 +41,7 @@ def __init__(
4141 meta : Optional [Meta ] = None ,
4242 vault_address : Optional [str ] = None ,
4343 account_address : Optional [str ] = None ,
44+ spot_meta : Optional [SpotMeta ] = None ,
4445 ):
4546 super ().__init__ (base_url )
4647 self .wallet = wallet
@@ -51,8 +52,18 @@ def __init__(
5152 self .meta = self .info .meta ()
5253 else :
5354 self .meta = meta
55+
56+ if spot_meta is None :
57+ self .spot_meta = self .info .spot_meta ()
58+ else :
59+ self .spot_meta = spot_meta
60+
5461 self .coin_to_asset = {asset_info ["name" ]: asset for (asset , asset_info ) in enumerate (self .meta ["universe" ])}
5562
63+ # spot assets start at 10000
64+ for i , spot_pair in enumerate (self .spot_meta ["universe" ]):
65+ self .coin_to_asset [spot_pair ["name" ]] = i + 10000
66+
5667 def _post_action (self , action , signature , nonce ):
5768 payload = {
5869 "action" : action ,
@@ -389,6 +400,29 @@ def create_sub_account(self, name: str) -> Any:
389400 timestamp ,
390401 )
391402
403+ def user_spot_transfer (self , usdc : float , to_perp : bool ) -> Any :
404+ usdc = int (round (usdc , 2 ) * 1e6 )
405+ timestamp = get_timestamp_ms ()
406+ spot_user_action = {
407+ "type" : "spotUser" ,
408+ "classTransfer" : {
409+ "usdc" : usdc ,
410+ "toPerp" : to_perp ,
411+ },
412+ }
413+ signature = sign_l1_action (
414+ self .wallet ,
415+ spot_user_action ,
416+ self .vault_address ,
417+ timestamp ,
418+ self .base_url == MAINNET_API_URL ,
419+ )
420+ return self ._post_action (
421+ spot_user_action ,
422+ signature ,
423+ timestamp ,
424+ )
425+
392426 def sub_account_transfer (self , sub_account_user : str , is_deposit : bool , usd : int ) -> Any :
393427 timestamp = get_timestamp_ms ()
394428 sub_account_transfer_action = {
0 commit comments