2020 get_timestamp_ms ,
2121 order_request_to_order_wire ,
2222 order_wires_to_order_action ,
23+ sign_approve_builder_fee ,
2324 sign_l1_action ,
25+ sign_usd_class_transfer_action ,
2426 sign_usd_transfer_action ,
2527 sign_spot_transfer_action ,
2628 sign_withdraw_from_bridge_action ,
2729 sign_agent ,
2830)
29- from hyperliquid .utils .types import Any , List , Meta , SpotMeta , Optional , Tuple , Cloid
31+ from hyperliquid .utils .types import Any , List , Meta , SpotMeta , Optional , Tuple , Cloid , BuilderInfo
3032
3133
3234class Exchange (API ):
@@ -87,6 +89,7 @@ def order(
8789 order_type : OrderType ,
8890 reduce_only : bool = False ,
8991 cloid : Optional [Cloid ] = None ,
92+ builder : Optional [BuilderInfo ] = None ,
9093 ) -> Any :
9194 order : OrderRequest = {
9295 "coin" : name ,
@@ -98,15 +101,15 @@ def order(
98101 }
99102 if cloid :
100103 order ["cloid" ] = cloid
101- return self .bulk_orders ([order ])
104+ return self .bulk_orders ([order ], builder )
102105
103- def bulk_orders (self , order_requests : List [OrderRequest ]) -> Any :
106+ def bulk_orders (self , order_requests : List [OrderRequest ], builder : Optional [ BuilderInfo ] = None ) -> Any :
104107 order_wires : List [OrderWire ] = [
105108 order_request_to_order_wire (order , self .info .name_to_asset (order ["coin" ])) for order in order_requests
106109 ]
107110 timestamp = get_timestamp_ms ()
108111
109- order_action = order_wires_to_order_action (order_wires )
112+ order_action = order_wires_to_order_action (order_wires , builder )
110113
111114 signature = sign_l1_action (
112115 self .wallet ,
@@ -184,11 +187,14 @@ def market_open(
184187 px : Optional [float ] = None ,
185188 slippage : float = DEFAULT_SLIPPAGE ,
186189 cloid : Optional [Cloid ] = None ,
190+ builder : Optional [BuilderInfo ] = None ,
187191 ) -> Any :
188192 # Get aggressive Market Price
189193 px = self ._slippage_price (name , is_buy , slippage , px )
190194 # Market Order is an aggressive Limit Order IoC
191- return self .order (name , is_buy , sz , px , order_type = {"limit" : {"tif" : "Ioc" }}, reduce_only = False , cloid = cloid )
195+ return self .order (
196+ name , is_buy , sz , px , order_type = {"limit" : {"tif" : "Ioc" }}, reduce_only = False , cloid = cloid , builder = builder
197+ )
192198
193199 def market_close (
194200 self ,
@@ -197,6 +203,7 @@ def market_close(
197203 px : Optional [float ] = None ,
198204 slippage : float = DEFAULT_SLIPPAGE ,
199205 cloid : Optional [Cloid ] = None ,
206+ builder : Optional [BuilderInfo ] = None ,
200207 ) -> Any :
201208 address = self .wallet .address
202209 if self .account_address :
@@ -215,7 +222,16 @@ def market_close(
215222 # Get aggressive Market Price
216223 px = self ._slippage_price (coin , is_buy , slippage , px )
217224 # Market Order is an aggressive Limit Order IoC
218- return self .order (coin , is_buy , sz , px , order_type = {"limit" : {"tif" : "Ioc" }}, reduce_only = True , cloid = cloid )
225+ return self .order (
226+ coin ,
227+ is_buy ,
228+ sz ,
229+ px ,
230+ order_type = {"limit" : {"tif" : "Ioc" }},
231+ reduce_only = True ,
232+ cloid = cloid ,
233+ builder = builder ,
234+ )
219235
220236 def cancel (self , name : str , oid : int ) -> Any :
221237 return self .bulk_cancel ([{"coin" : name , "oid" : oid }])
@@ -384,6 +400,22 @@ def create_sub_account(self, name: str) -> Any:
384400 timestamp ,
385401 )
386402
403+ def usd_class_transfer (self , amount : float , to_perp : bool ) -> Any :
404+ timestamp = get_timestamp_ms ()
405+ action = {
406+ "type" : "usdClassTransfer" ,
407+ "amount" : str (amount ),
408+ "toPerp" : to_perp ,
409+ "nonce" : timestamp ,
410+ }
411+ signature = sign_usd_class_transfer_action (self .wallet , action , self .base_url == MAINNET_API_URL )
412+ return self ._post_action (
413+ action ,
414+ signature ,
415+ timestamp ,
416+ )
417+
418+ # Deprecated in favor of usd_class_transfer
387419 def user_spot_transfer (self , usdc : float , to_perp : bool ) -> Any :
388420 usdc = int (round (usdc , 2 ) * 1e6 )
389421 timestamp = get_timestamp_ms ()
@@ -427,22 +459,21 @@ def sub_account_transfer(self, sub_account_user: str, is_deposit: bool, usd: int
427459 signature ,
428460 timestamp ,
429461 )
430-
462+
431463 def vault_usd_transfer (self , vault_address : str , is_deposit : bool , usd : int ) -> Any :
432464 timestamp = get_timestamp_ms ()
433465 vault_transfer_action = {
434466 "type" : "vaultTransfer" ,
435467 "vaultAddress" : vault_address ,
436468 "isDeposit" : is_deposit ,
437- "usd" : usd }
469+ "usd" : usd ,
470+ }
438471 is_mainnet = self .base_url == MAINNET_API_URL
439472 signature = sign_l1_action (self .wallet , vault_transfer_action , None , timestamp , is_mainnet )
440- return (
441- self ._post_action (
442- vault_transfer_action ,
443- signature ,
444- timestamp ,
445- )
473+ return self ._post_action (
474+ vault_transfer_action ,
475+ signature ,
476+ timestamp ,
446477 )
447478
448479 def usd_transfer (self , amount : float , destination : str ) -> Any :
@@ -458,8 +489,13 @@ def usd_transfer(self, amount: float, destination: str) -> Any:
458489
459490 def spot_transfer (self , amount : float , destination : str , token : str ) -> Any :
460491 timestamp = get_timestamp_ms ()
461- action = {"destination" : destination , "amount" : str (
462- amount ), "token" : token , "time" : timestamp , "type" : "spotSend" }
492+ action = {
493+ "destination" : destination ,
494+ "amount" : str (amount ),
495+ "token" : token ,
496+ "time" : timestamp ,
497+ "type" : "spotSend" ,
498+ }
463499 is_mainnet = self .base_url == MAINNET_API_URL
464500 signature = sign_spot_transfer_action (self .wallet , action , is_mainnet )
465501 return self ._post_action (
@@ -502,3 +538,10 @@ def approve_agent(self, name: Optional[str] = None) -> Tuple[Any, str]:
502538 ),
503539 agent_key ,
504540 )
541+
542+ def approve_builder_fee (self , builder : str , max_fee_rate : str ) -> Any :
543+ timestamp = get_timestamp_ms ()
544+
545+ action = {"maxFeeRate" : max_fee_rate , "builder" : builder , "nonce" : timestamp , "type" : "approveBuilderFee" }
546+ signature = sign_approve_builder_fee (self .wallet , action , self .base_url == MAINNET_API_URL )
547+ return self ._post_action (action , signature , timestamp )
0 commit comments