11
11
from hyperliquid .utils .signing import (
12
12
CancelByCloidRequest ,
13
13
CancelRequest ,
14
+ Grouping ,
14
15
ModifyRequest ,
15
16
OidOrCloid ,
16
17
OrderRequest ,
31
32
sign_usd_transfer_action ,
32
33
sign_withdraw_from_bridge_action ,
33
34
)
34
- from hyperliquid .utils .types import Any , BuilderInfo , Cloid , List , Meta , Optional , SpotMeta , Tuple
35
+ from hyperliquid .utils .types import (
36
+ Any ,
37
+ BuilderInfo ,
38
+ Cloid ,
39
+ List ,
40
+ Meta ,
41
+ Optional ,
42
+ SpotMeta ,
43
+ Tuple ,
44
+ )
35
45
36
46
37
47
class Exchange (API ):
@@ -58,7 +68,9 @@ def _post_action(self, action, signature, nonce):
58
68
"action" : action ,
59
69
"nonce" : nonce ,
60
70
"signature" : signature ,
61
- "vaultAddress" : self .vault_address if action ["type" ] != "usdClassTransfer" else None ,
71
+ "vaultAddress" : self .vault_address
72
+ if action ["type" ] != "usdClassTransfer"
73
+ else None ,
62
74
}
63
75
logging .debug (payload )
64
76
return self .post ("/exchange" , payload )
@@ -93,6 +105,7 @@ def order(
93
105
reduce_only : bool = False ,
94
106
cloid : Optional [Cloid ] = None ,
95
107
builder : Optional [BuilderInfo ] = None ,
108
+ grouping : Grouping = "na" ,
96
109
) -> Any :
97
110
order : OrderRequest = {
98
111
"coin" : name ,
@@ -104,17 +117,23 @@ def order(
104
117
}
105
118
if cloid :
106
119
order ["cloid" ] = cloid
107
- return self .bulk_orders ([order ], builder )
120
+ return self .bulk_orders ([order ], builder , grouping )
108
121
109
- def bulk_orders (self , order_requests : List [OrderRequest ], builder : Optional [BuilderInfo ] = None ) -> Any :
122
+ def bulk_orders (
123
+ self ,
124
+ order_requests : List [OrderRequest ],
125
+ builder : Optional [BuilderInfo ] = None ,
126
+ grouping : Grouping = "na" ,
127
+ ) -> Any :
110
128
order_wires : List [OrderWire ] = [
111
- order_request_to_order_wire (order , self .info .name_to_asset (order ["coin" ])) for order in order_requests
129
+ order_request_to_order_wire (order , self .info .name_to_asset (order ["coin" ]))
130
+ for order in order_requests
112
131
]
113
132
timestamp = get_timestamp_ms ()
114
133
115
134
if builder :
116
135
builder ["b" ] = builder ["b" ].lower ()
117
- order_action = order_wires_to_order_action (order_wires , builder )
136
+ order_action = order_wires_to_order_action (order_wires , builder , grouping )
118
137
119
138
signature = sign_l1_action (
120
139
self .wallet ,
@@ -159,8 +178,12 @@ def bulk_modify_orders_new(self, modify_requests: List[ModifyRequest]) -> Any:
159
178
timestamp = get_timestamp_ms ()
160
179
modify_wires = [
161
180
{
162
- "oid" : modify ["oid" ].to_raw () if isinstance (modify ["oid" ], Cloid ) else modify ["oid" ],
163
- "order" : order_request_to_order_wire (modify ["order" ], self .info .name_to_asset (modify ["order" ]["coin" ])),
181
+ "oid" : modify ["oid" ].to_raw ()
182
+ if isinstance (modify ["oid" ], Cloid )
183
+ else modify ["oid" ],
184
+ "order" : order_request_to_order_wire (
185
+ modify ["order" ], self .info .name_to_asset (modify ["order" ]["coin" ])
186
+ ),
164
187
}
165
188
for modify in modify_requests
166
189
]
@@ -198,7 +221,14 @@ def market_open(
198
221
px = self ._slippage_price (name , is_buy , slippage , px )
199
222
# Market Order is an aggressive Limit Order IoC
200
223
return self .order (
201
- name , is_buy , sz , px , order_type = {"limit" : {"tif" : "Ioc" }}, reduce_only = False , cloid = cloid , builder = builder
224
+ name ,
225
+ is_buy ,
226
+ sz ,
227
+ px ,
228
+ order_type = {"limit" : {"tif" : "Ioc" }},
229
+ reduce_only = False ,
230
+ cloid = cloid ,
231
+ builder = builder ,
202
232
)
203
233
204
234
def market_close (
@@ -417,14 +447,18 @@ def usd_class_transfer(self, amount: float, to_perp: bool) -> Any:
417
447
"toPerp" : to_perp ,
418
448
"nonce" : timestamp ,
419
449
}
420
- signature = sign_usd_class_transfer_action (self .wallet , action , self .base_url == MAINNET_API_URL )
450
+ signature = sign_usd_class_transfer_action (
451
+ self .wallet , action , self .base_url == MAINNET_API_URL
452
+ )
421
453
return self ._post_action (
422
454
action ,
423
455
signature ,
424
456
timestamp ,
425
457
)
426
458
427
- def sub_account_transfer (self , sub_account_user : str , is_deposit : bool , usd : int ) -> Any :
459
+ def sub_account_transfer (
460
+ self , sub_account_user : str , is_deposit : bool , usd : int
461
+ ) -> Any :
428
462
timestamp = get_timestamp_ms ()
429
463
sub_account_transfer_action = {
430
464
"type" : "subAccountTransfer" ,
@@ -445,7 +479,9 @@ def sub_account_transfer(self, sub_account_user: str, is_deposit: bool, usd: int
445
479
timestamp ,
446
480
)
447
481
448
- def sub_account_spot_transfer (self , sub_account_user : str , is_deposit : bool , token : str , amount : float ) -> Any :
482
+ def sub_account_spot_transfer (
483
+ self , sub_account_user : str , is_deposit : bool , token : str , amount : float
484
+ ) -> Any :
449
485
timestamp = get_timestamp_ms ()
450
486
sub_account_transfer_action = {
451
487
"type" : "subAccountSpotTransfer" ,
@@ -476,7 +512,9 @@ def vault_usd_transfer(self, vault_address: str, is_deposit: bool, usd: int) ->
476
512
"usd" : usd ,
477
513
}
478
514
is_mainnet = self .base_url == MAINNET_API_URL
479
- signature = sign_l1_action (self .wallet , vault_transfer_action , None , timestamp , is_mainnet )
515
+ signature = sign_l1_action (
516
+ self .wallet , vault_transfer_action , None , timestamp , is_mainnet
517
+ )
480
518
return self ._post_action (
481
519
vault_transfer_action ,
482
520
signature ,
@@ -485,7 +523,12 @@ def vault_usd_transfer(self, vault_address: str, is_deposit: bool, usd: int) ->
485
523
486
524
def usd_transfer (self , amount : float , destination : str ) -> Any :
487
525
timestamp = get_timestamp_ms ()
488
- action = {"destination" : destination , "amount" : str (amount ), "time" : timestamp , "type" : "usdSend" }
526
+ action = {
527
+ "destination" : destination ,
528
+ "amount" : str (amount ),
529
+ "time" : timestamp ,
530
+ "type" : "usdSend" ,
531
+ }
489
532
is_mainnet = self .base_url == MAINNET_API_URL
490
533
signature = sign_usd_transfer_action (self .wallet , action , is_mainnet )
491
534
return self ._post_action (
@@ -513,7 +556,12 @@ def spot_transfer(self, amount: float, destination: str, token: str) -> Any:
513
556
514
557
def withdraw_from_bridge (self , amount : float , destination : str ) -> Any :
515
558
timestamp = get_timestamp_ms ()
516
- action = {"destination" : destination , "amount" : str (amount ), "time" : timestamp , "type" : "withdraw3" }
559
+ action = {
560
+ "destination" : destination ,
561
+ "amount" : str (amount ),
562
+ "time" : timestamp ,
563
+ "type" : "withdraw3" ,
564
+ }
517
565
is_mainnet = self .base_url == MAINNET_API_URL
518
566
signature = sign_withdraw_from_bridge_action (self .wallet , action , is_mainnet )
519
567
return self ._post_action (
@@ -549,11 +597,20 @@ def approve_agent(self, name: Optional[str] = None) -> Tuple[Any, str]:
549
597
def approve_builder_fee (self , builder : str , max_fee_rate : str ) -> Any :
550
598
timestamp = get_timestamp_ms ()
551
599
552
- action = {"maxFeeRate" : max_fee_rate , "builder" : builder , "nonce" : timestamp , "type" : "approveBuilderFee" }
553
- signature = sign_approve_builder_fee (self .wallet , action , self .base_url == MAINNET_API_URL )
600
+ action = {
601
+ "maxFeeRate" : max_fee_rate ,
602
+ "builder" : builder ,
603
+ "nonce" : timestamp ,
604
+ "type" : "approveBuilderFee" ,
605
+ }
606
+ signature = sign_approve_builder_fee (
607
+ self .wallet , action , self .base_url == MAINNET_API_URL
608
+ )
554
609
return self ._post_action (action , signature , timestamp )
555
610
556
- def convert_to_multi_sig_user (self , authorized_users : List [str ], threshold : int ) -> Any :
611
+ def convert_to_multi_sig_user (
612
+ self , authorized_users : List [str ], threshold : int
613
+ ) -> Any :
557
614
timestamp = get_timestamp_ms ()
558
615
authorized_users = sorted (authorized_users )
559
616
signers = {
@@ -565,14 +622,18 @@ def convert_to_multi_sig_user(self, authorized_users: List[str], threshold: int)
565
622
"signers" : json .dumps (signers ),
566
623
"nonce" : timestamp ,
567
624
}
568
- signature = sign_convert_to_multi_sig_user_action (self .wallet , action , self .base_url == MAINNET_API_URL )
625
+ signature = sign_convert_to_multi_sig_user_action (
626
+ self .wallet , action , self .base_url == MAINNET_API_URL
627
+ )
569
628
return self ._post_action (
570
629
action ,
571
630
signature ,
572
631
timestamp ,
573
632
)
574
633
575
- def multi_sig (self , multi_sig_user , inner_action , signatures , nonce , vault_address = None ):
634
+ def multi_sig (
635
+ self , multi_sig_user , inner_action , signatures , nonce , vault_address = None
636
+ ):
576
637
multi_sig_user = multi_sig_user .lower ()
577
638
multi_sig_action = {
578
639
"type" : "multiSig" ,
0 commit comments