hyperliquid-sdk 0.7.2__tar.gz → 0.7.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/PKG-INFO +297 -111
  2. hyperliquid_sdk-0.7.4/README.md +762 -0
  3. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/__init__.py +7 -1
  4. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/client.py +335 -48
  5. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/order.py +36 -6
  6. hyperliquid_sdk-0.7.4/hyperliquid_sdk/prediction.py +225 -0
  7. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/pyproject.toml +1 -1
  8. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/test_order.py +11 -0
  9. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/test_sdk.py +164 -0
  10. hyperliquid_sdk-0.7.2/README.md +0 -576
  11. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/.gitignore +0 -0
  12. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/LICENSE +0 -0
  13. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/errors.py +0 -0
  14. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/evm.py +0 -0
  15. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/evm_stream.py +0 -0
  16. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/grpc_stream.py +0 -0
  17. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/hypercore.py +0 -0
  18. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/info.py +0 -0
  19. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/__init__.py +0 -0
  20. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/orderbook.proto +0 -0
  21. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/orderbook_pb2.py +0 -0
  22. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/orderbook_pb2_grpc.py +0 -0
  23. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/streaming.proto +0 -0
  24. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/streaming_pb2.py +0 -0
  25. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/proto/streaming_pb2_grpc.py +0 -0
  26. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/py.typed +0 -0
  27. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/hyperliquid_sdk/websocket.py +0 -0
  28. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/__init__.py +0 -0
  29. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/conftest.py +0 -0
  30. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/test_hypercore.py +0 -0
  31. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/test_info.py +0 -0
  32. {hyperliquid_sdk-0.7.2 → hyperliquid_sdk-0.7.4}/tests/test_websocket.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyperliquid-sdk
3
- Version: 0.7.2
3
+ Version: 0.7.4
4
4
  Summary: Community SDK for Hyperliquid. One line to place orders, zero ceremony. HyperCore, HyperEVM, WebSocket and gRPC streams. Not affiliated with Hyperliquid Foundation.
5
5
  Project-URL: Homepage, https://hyperliquidapi.com
6
6
  Project-URL: Documentation, https://www.quicknode.com/docs/hyperliquid/api-overview
@@ -64,6 +64,23 @@ Everything is included: trading, market data, WebSocket streaming, gRPC streamin
64
64
 
65
65
  ## Quick Start
66
66
 
67
+ ### Try without an account (read-only)
68
+
69
+ All market data APIs work without a private key or QuickNode account — great for exploration:
70
+
71
+ ```python
72
+ from hyperliquid_sdk import HyperliquidSDK
73
+
74
+ sdk = HyperliquidSDK("https://api.hyperliquid.xyz") # Public endpoint, no auth needed
75
+
76
+ # Fetch live market data right away
77
+ print(sdk.info.all_mids()) # All mid prices
78
+ print(sdk.info.meta()) # Exchange metadata (229 perp markets)
79
+ print(sdk.info.l2_book("BTC")) # BTC order book
80
+ ```
81
+
82
+ To place orders, set up a private key and use a [QuickNode Hyperliquid endpoint](https://www.quicknode.com/).
83
+
67
84
  ### 1. Set your private key
68
85
 
69
86
  ```bash
@@ -105,64 +122,67 @@ You can create a Hyperliquid endpoint on [Quicknode](https://www.quicknode.com/)
105
122
  sdk = HyperliquidSDK(endpoint)
106
123
 
107
124
  # Market data
108
- sdk.info().all_mids() # All mid prices
109
- sdk.info().l2_book("BTC") # Order book
110
- sdk.info().recent_trades("BTC") # Recent trades
111
- sdk.info().candles("BTC", "1h", start, end) # OHLCV candles
112
- sdk.info().funding_history("BTC", start, end) # Funding history
113
- sdk.info().predicted_fundings() # Predicted funding rates
125
+ sdk.info.all_mids() # All mid prices
126
+ sdk.info.l2_book("BTC") # Order book
127
+ sdk.info.recent_trades("BTC") # Recent trades
128
+ sdk.info.candles("BTC", "1h", start, end) # OHLCV candles
129
+ sdk.info.funding_history("BTC", start, end) # Funding history
130
+ sdk.info.predicted_fundings() # Predicted funding rates
131
+ # Note: predicted_fundings() returns rates from multiple sources (HlPerp, BinPerp, BybitPerp).
132
+ # Each source uses a different funding interval (1h, 8h, or variable). Always normalise
133
+ # by the returned `fundingIntervalHours` field before comparing rates across exchanges.
114
134
 
115
135
  # Metadata
116
- sdk.info().meta() # Exchange metadata
117
- sdk.info().spot_meta() # Spot metadata
118
- sdk.info().exchange_status() # Exchange status
119
- sdk.info().perp_dexs() # Perpetual DEX info
120
- sdk.info().max_market_order_ntls() # Max market order notionals
136
+ sdk.info.meta() # Exchange metadata
137
+ sdk.info.spot_meta() # Spot metadata
138
+ sdk.info.exchange_status() # Exchange status
139
+ sdk.info.perp_dexs() # Perpetual DEX info
140
+ sdk.info.max_market_order_ntls() # Max market order notionals
121
141
 
122
142
  # User data
123
- sdk.info().clearinghouse_state("0x...") # Positions & margin
124
- sdk.info().spot_clearinghouse_state("0x...") # Spot balances
125
- sdk.info().open_orders("0x...") # Open orders
126
- sdk.info().frontend_open_orders("0x...") # Enhanced open orders
127
- sdk.info().order_status("0x...", oid) # Specific order status
128
- sdk.info().historical_orders("0x...") # Order history
129
- sdk.info().user_fills("0x...") # Trade history
130
- sdk.info().user_fills_by_time("0x...", start) # Fills by time range
131
- sdk.info().user_funding("0x...") # Funding payments
132
- sdk.info().user_fees("0x...") # Fee structure
133
- sdk.info().user_rate_limit("0x...") # Rate limit status
134
- sdk.info().user_role("0x...") # Account type
135
- sdk.info().portfolio("0x...") # Portfolio history
136
- sdk.info().sub_accounts("0x...") # Sub-accounts
137
- sdk.info().extra_agents("0x...") # API keys/agents
143
+ sdk.info.clearinghouse_state("0x...") # Positions & margin
144
+ sdk.info.spot_clearinghouse_state("0x...") # Spot balances
145
+ sdk.info.open_orders("0x...") # Open orders
146
+ sdk.info.frontend_open_orders("0x...") # Enhanced open orders
147
+ sdk.info.order_status("0x...", oid) # Specific order status
148
+ sdk.info.historical_orders("0x...") # Order history
149
+ sdk.info.user_fills("0x...") # Trade history
150
+ sdk.info.user_fills_by_time("0x...", start) # Fills by time range
151
+ sdk.info.user_funding("0x...") # Funding payments
152
+ sdk.info.user_fees("0x...") # Fee structure
153
+ sdk.info.user_rate_limit("0x...") # Rate limit status
154
+ sdk.info.user_role("0x...") # Account type
155
+ sdk.info.portfolio("0x...") # Portfolio history
156
+ sdk.info.sub_accounts("0x...") # Sub-accounts
157
+ sdk.info.extra_agents("0x...") # API keys/agents
138
158
 
139
159
  # TWAP
140
- sdk.info().user_twap_slice_fills("0x...") # TWAP slice fills
160
+ sdk.info.user_twap_slice_fills("0x...") # TWAP slice fills
141
161
 
142
162
  # Batch queries
143
- sdk.info().batch_clearinghouse_states(["0x...", "0x..."])
163
+ sdk.info.batch_clearinghouse_states(["0x...", "0x..."])
144
164
 
145
165
  # Vaults
146
- sdk.info().vault_summaries() # All vault summaries
147
- sdk.info().vault_details("0x...") # Specific vault
148
- sdk.info().user_vault_equities("0x...") # User's vault equities
149
- sdk.info().leading_vaults("0x...") # Vaults user leads
166
+ sdk.info.vault_summaries() # All vault summaries
167
+ sdk.info.vault_details("0x...") # Specific vault
168
+ sdk.info.user_vault_equities("0x...") # User's vault equities
169
+ sdk.info.leading_vaults("0x...") # Vaults user leads
150
170
 
151
171
  # Delegation/Staking
152
- sdk.info().delegations("0x...") # Active delegations
153
- sdk.info().delegator_summary("0x...") # Delegation summary
154
- sdk.info().delegator_history("0x...") # Delegation history
155
- sdk.info().delegator_rewards("0x...") # Delegation rewards
172
+ sdk.info.delegations("0x...") # Active delegations
173
+ sdk.info.delegator_summary("0x...") # Delegation summary
174
+ sdk.info.delegator_history("0x...") # Delegation history
175
+ sdk.info.delegator_rewards("0x...") # Delegation rewards
156
176
 
157
177
  # Tokens
158
- sdk.info().token_details("token_id") # Token details
159
- sdk.info().spot_deploy_state("0x...") # Spot deployment state
178
+ sdk.info.token_details("token_id") # Token details
179
+ sdk.info.spot_deploy_state("0x...") # Spot deployment state
160
180
 
161
181
  # Other
162
- sdk.info().referral("0x...") # Referral info
163
- sdk.info().max_builder_fee("0x...", "0x...") # Builder fee limits
164
- sdk.info().approved_builders("0x...") # Approved builders
165
- sdk.info().liquidatable() # Liquidatable positions
182
+ sdk.info.referral("0x...") # Referral info
183
+ sdk.info.max_builder_fee("0x...", "0x...") # Builder fee limits
184
+ sdk.info.approved_builders("0x...") # Approved builders
185
+ sdk.info.liquidatable() # Liquidatable positions
166
186
  ```
167
187
 
168
188
  ### HyperCore API
@@ -173,26 +193,26 @@ Block data, trading operations, and real-time data via JSON-RPC.
173
193
  sdk = HyperliquidSDK(endpoint)
174
194
 
175
195
  # Block data
176
- sdk.core().latest_block_number() # Latest block
177
- sdk.core().get_block(12345) # Get specific block
178
- sdk.core().get_batch_blocks(100, 110) # Get block range
179
- sdk.core().latest_blocks(count=10) # Latest blocks
196
+ sdk.core.latest_block_number() # Latest block
197
+ sdk.core.get_block(12345) # Get specific block
198
+ sdk.core.get_batch_blocks(100, 110) # Get block range
199
+ sdk.core.latest_blocks(count=10) # Latest blocks
180
200
 
181
201
  # Recent data
182
- sdk.core().latest_trades(count=10) # Recent trades (all coins)
183
- sdk.core().latest_trades(count=10, coin="BTC") # Recent BTC trades
184
- sdk.core().latest_orders(count=10) # Recent order events
185
- sdk.core().latest_book_updates(count=10) # Recent book updates
202
+ sdk.core.latest_trades(count=10) # Recent trades (all coins)
203
+ sdk.core.latest_trades(count=10, coin="BTC") # Recent BTC trades
204
+ sdk.core.latest_orders(count=10) # Recent order events
205
+ sdk.core.latest_book_updates(count=10) # Recent book updates
186
206
 
187
207
  # Discovery
188
- sdk.core().list_dexes() # All DEXes
189
- sdk.core().list_markets() # All markets
190
- sdk.core().list_markets(dex="hyperliquidity") # Markets by DEX
208
+ sdk.core.list_dexes() # All DEXes
209
+ sdk.core.list_markets() # All markets
210
+ sdk.core.list_markets(dex="hyperliquidity") # Markets by DEX
191
211
 
192
212
  # Order queries
193
- sdk.core().open_orders("0x...") # User's open orders
194
- sdk.core().order_status("0x...", oid) # Specific order status
195
- sdk.core().preflight(...) # Validate order before signing
213
+ sdk.core.open_orders("0x...") # User's open orders
214
+ sdk.core.order_status("0x...", oid) # Specific order status
215
+ sdk.core.preflight(...) # Validate order before signing
196
216
  ```
197
217
 
198
218
  ### EVM (Ethereum JSON-RPC)
@@ -203,45 +223,45 @@ sdk.core().preflight(...) # Validate order before signing
203
223
  sdk = HyperliquidSDK(endpoint)
204
224
 
205
225
  # Chain info
206
- sdk.evm().block_number() # Latest block
207
- sdk.evm().chain_id() # 999 mainnet, 998 testnet
208
- sdk.evm().gas_price() # Current gas price
209
- sdk.evm().max_priority_fee_per_gas() # Priority fee
210
- sdk.evm().net_version() # Network version
211
- sdk.evm().syncing() # Sync status
226
+ sdk.evm.block_number() # Latest block
227
+ sdk.evm.chain_id() # 999 mainnet, 998 testnet
228
+ sdk.evm.gas_price() # Current gas price
229
+ sdk.evm.max_priority_fee_per_gas() # Priority fee
230
+ sdk.evm.net_version() # Network version
231
+ sdk.evm.syncing() # Sync status
212
232
 
213
233
  # Accounts
214
- sdk.evm().get_balance("0x...") # Account balance
215
- sdk.evm().get_transaction_count("0x...") # Nonce
216
- sdk.evm().get_code("0x...") # Contract code
217
- sdk.evm().get_storage_at("0x...", position) # Storage value
234
+ sdk.evm.get_balance("0x...") # Account balance
235
+ sdk.evm.get_transaction_count("0x...") # Nonce
236
+ sdk.evm.get_code("0x...") # Contract code
237
+ sdk.evm.get_storage_at("0x...", position) # Storage value
218
238
 
219
239
  # Transactions
220
- sdk.evm().call({"to": "0x...", "data": "0x..."})
221
- sdk.evm().estimate_gas(tx)
222
- sdk.evm().send_raw_transaction(signed_tx)
223
- sdk.evm().get_transaction_by_hash("0x...")
224
- sdk.evm().get_transaction_receipt("0x...")
240
+ sdk.evm.call({"to": "0x...", "data": "0x..."})
241
+ sdk.evm.estimate_gas(tx)
242
+ sdk.evm.send_raw_transaction(signed_tx)
243
+ sdk.evm.get_transaction_by_hash("0x...")
244
+ sdk.evm.get_transaction_receipt("0x...")
225
245
 
226
246
  # Blocks
227
- sdk.evm().get_block_by_number(12345)
228
- sdk.evm().get_block_by_hash("0x...")
229
- sdk.evm().get_block_receipts(12345)
230
- sdk.evm().get_block_transaction_count_by_number(12345)
247
+ sdk.evm.get_block_by_number(12345)
248
+ sdk.evm.get_block_by_hash("0x...")
249
+ sdk.evm.get_block_receipts(12345)
250
+ sdk.evm.get_block_transaction_count_by_number(12345)
231
251
 
232
252
  # Logs
233
- sdk.evm().get_logs({"address": "0x...", "topics": [...]})
253
+ sdk.evm.get_logs({"address": "0x...", "topics": [...]})
234
254
 
235
255
  # HyperEVM-specific
236
- sdk.evm().big_block_gas_price() # Big block gas price
237
- sdk.evm().using_big_blocks() # Is using big blocks?
238
- sdk.evm().get_system_txs_by_block_number(12345)
256
+ sdk.evm.big_block_gas_price() # Big block gas price
257
+ sdk.evm.using_big_blocks() # Is using big blocks?
258
+ sdk.evm.get_system_txs_by_block_number(12345)
239
259
 
240
260
  # Debug/Trace
241
- sdk.evm().debug_trace_transaction("0x...", {"tracer": "callTracer"})
242
- sdk.evm().debug_trace_block_by_number(12345)
243
- sdk.evm().trace_transaction("0x...")
244
- sdk.evm().trace_block(12345)
261
+ sdk.evm.debug_trace_transaction("0x...", {"tracer": "callTracer"})
262
+ sdk.evm.debug_trace_block_by_number(12345)
263
+ sdk.evm.trace_transaction("0x...")
264
+ sdk.evm.trace_block(12345)
245
265
  ```
246
266
 
247
267
  ---
@@ -256,21 +276,21 @@ sdk.evm().trace_block(12345)
256
276
  sdk = HyperliquidSDK(endpoint)
257
277
 
258
278
  # Subscribe to trades
259
- sdk.stream().trades(["BTC", "ETH"], lambda t: print(f"Trade: {t}"))
279
+ sdk.stream.trades(["BTC", "ETH"], lambda t: print(f"Trade: {t}"))
260
280
 
261
281
  # Subscribe to book updates
262
- sdk.stream().book_updates(["BTC"], lambda b: print(f"Book: {b}"))
282
+ sdk.stream.book_updates(["BTC"], lambda b: print(f"Book: {b}"))
263
283
 
264
284
  # Subscribe to orders (your orders)
265
- sdk.stream().orders(["BTC"], lambda o: print(f"Order: {o}"), users=["0x..."])
285
+ sdk.stream.orders(["BTC"], lambda o: print(f"Order: {o}"), users=["0x..."])
266
286
 
267
287
  # Run in background
268
- sdk.stream().start()
288
+ sdk.stream.start()
269
289
  # ... do other work ...
270
- sdk.stream().stop()
290
+ sdk.stream.stop()
271
291
 
272
292
  # Or run blocking
273
- sdk.stream().run()
293
+ sdk.stream.run()
274
294
  ```
275
295
 
276
296
  Available streams:
@@ -314,24 +334,24 @@ Lower latency streaming via gRPC for high-frequency applications.
314
334
  sdk = HyperliquidSDK(endpoint)
315
335
 
316
336
  # Subscribe to trades
317
- sdk.grpc().trades(["BTC", "ETH"], lambda t: print(f"Trade: {t}"))
337
+ sdk.grpc.trades(["BTC", "ETH"], lambda t: print(f"Trade: {t}"))
318
338
 
319
339
  # Subscribe to L2 order book (aggregated by price level)
320
- sdk.grpc().l2_book("BTC", lambda b: print(f"Book: {b}"), n_sig_figs=5)
340
+ sdk.grpc.l2_book("BTC", lambda b: print(f"Book: {b}"), n_sig_figs=5)
321
341
 
322
342
  # Subscribe to L4 order book (CRITICAL: individual orders with order IDs)
323
- sdk.grpc().l4_book("BTC", lambda b: print(f"L4: {b}"))
343
+ sdk.grpc.l4_book("BTC", lambda b: print(f"L4: {b}"))
324
344
 
325
345
  # Subscribe to blocks
326
- sdk.grpc().blocks(lambda b: print(f"Block: {b}"))
346
+ sdk.grpc.blocks(lambda b: print(f"Block: {b}"))
327
347
 
328
348
  # Run in background
329
- sdk.grpc().start()
349
+ sdk.grpc.start()
330
350
  # ... do other work ...
331
- sdk.grpc().stop()
351
+ sdk.grpc.stop()
332
352
 
333
353
  # Or run blocking
334
- sdk.grpc().run()
354
+ sdk.grpc.run()
335
355
  ```
336
356
 
337
357
  **Available gRPC Streams:**
@@ -371,8 +391,8 @@ def on_l4_book(data):
371
391
  print(f"Bid: ${float(px):,.2f} x {sz} (order: {oid})")
372
392
 
373
393
  sdk = HyperliquidSDK(endpoint)
374
- sdk.grpc().l4_book("BTC", on_l4_book)
375
- sdk.grpc().run()
394
+ sdk.grpc.l4_book("BTC", on_l4_book)
395
+ sdk.grpc.run()
376
396
  ```
377
397
 
378
398
  ### L2 vs L4 Comparison
@@ -401,11 +421,35 @@ sdk.market_sell("ETH", notional=100)
401
421
  sdk.buy("BTC", size=0.001, price=65000)
402
422
  sdk.sell("ETH", size=0.5, price=4000, tif="gtc")
403
423
 
424
+ # Order priority. priority_fee=10000 is 1 bp.
425
+ # Priority fees are paid from undelegated staking HYPE.
426
+ sdk.fund_priority_fees(0.001)
427
+ sdk.market_buy("HYPE", size=0.3, priority_fee=10000)
428
+
404
429
  # Perp trader aliases
405
430
  sdk.long("BTC", size=0.001, price=65000)
406
431
  sdk.short("ETH", notional=500, tif="ioc")
407
432
  ```
408
433
 
434
+ ### HIP-4 Prediction Markets
435
+
436
+ Always discover the active markets first. The returned `market.yes` and `market.no` sides are directly tradeable, so users do not need to memorize `#10` or the native asset id.
437
+
438
+ ```python
439
+ markets = sdk.prediction_markets()
440
+ for market in markets:
441
+ print(market.title, market.yes.symbol, market.yes.mid, market.no.symbol, market.no.mid)
442
+
443
+ market = markets.find(underlying="BTC", target_price="78213")
444
+
445
+ # HIP-4 uses USDH collateral and a 10 USDH minimum order value.
446
+ sdk.buy_usdh(10.7)
447
+ order = sdk.buy(market.yes, size=20, price="0.63")
448
+ exit_order = sdk.sell(market.yes, size=20, price="0.64")
449
+ ```
450
+
451
+ HIP-4 sizes must be whole contracts. Priority fees are not supported for HIP-4, so omit `priority_fee` when trading `market.yes`, `market.no`, or raw `#` markets.
452
+
409
453
  ### Order Management
410
454
 
411
455
  ```python
@@ -429,6 +473,139 @@ sdk.schedule_cancel(int(time.time() * 1000) + 60000)
429
473
  sdk.close_position("BTC") # Close entire position
430
474
  ```
431
475
 
476
+ ### Querying Open Orders by Trading Pair
477
+
478
+ ```python
479
+ # Get all open orders
480
+ result = sdk.open_orders()
481
+ print(f"Total open orders: {len(result['orders'])}")
482
+
483
+ # Order fields: coin, limitPx (price), sz (size), side, oid, timestamp,
484
+ # orderType, tif, cloid, reduceOnly
485
+ for order in result['orders']:
486
+ print(f"{order['coin']} {order['side']} {order['sz']}@{order['limitPx']}")
487
+
488
+ # Filter by trading pair
489
+ btc_orders = [o for o in result['orders'] if o['coin'] == 'BTC']
490
+ for order in btc_orders:
491
+ print(f" {order['side']} {order['sz']} @ {order['limitPx']} | "
492
+ f"type={order['orderType']} tif={order['tif']} oid={order['oid']}")
493
+
494
+ # For enhanced data (triggers, children), use frontend_open_orders()
495
+ enhanced = sdk.info.frontend_open_orders(sdk.address)
496
+ ```
497
+
498
+ ### Partial Position Close by Percentage
499
+
500
+ `close_position()` closes the entire position. To close a percentage, read the current size and place a reduce-only market order for the desired amount:
501
+
502
+ ```python
503
+ def close_percentage(sdk, coin: str, percent: float):
504
+ """Close a percentage (0-100) of an open position."""
505
+ state = sdk.info.clearinghouse_state(sdk.address)
506
+ position = next(
507
+ (p for p in state['assetPositions'] if p['position']['coin'] == coin), None
508
+ )
509
+ if position is None:
510
+ raise ValueError(f"No open position for {coin}")
511
+
512
+ # szi is signed: positive = long, negative = short
513
+ szi = float(position['position']['szi'])
514
+ # Note: round close_size to asset's size decimals in production
515
+ close_size = abs(szi) * (percent / 100)
516
+
517
+ if szi > 0:
518
+ # Long position: sell to close
519
+ sdk.sell(coin, size=close_size, tif="market", reduce_only=True)
520
+ else:
521
+ # Short position: buy to close
522
+ sdk.buy(coin, size=close_size, tif="market", reduce_only=True)
523
+
524
+ # Close 50% of BTC position
525
+ close_percentage(sdk, "BTC", 50)
526
+ ```
527
+
528
+ ### Batch Cancel with Partial Failure Handling
529
+
530
+ Cancel all orders for an asset in one call:
531
+
532
+ ```python
533
+ # Cancel all orders for a specific asset
534
+ sdk.cancel_all("BTC")
535
+
536
+ # Cancel by client order ID (for CLOID-tracked orders)
537
+ sdk.cancel_by_cloid("0xmycloid...", "BTC")
538
+ ```
539
+
540
+ Or cancel selectively with per-order error handling:
541
+
542
+ ```python
543
+ from hyperliquid_sdk import HyperliquidError
544
+
545
+ # Get open orders
546
+ result = sdk.open_orders()
547
+
548
+ # Cancel specific orders with per-order error handling
549
+ target_orders = [o for o in result['orders']
550
+ if o['coin'] == 'BTC' and float(o['limitPx']) < 50000]
551
+ failures = []
552
+ for order in target_orders:
553
+ try:
554
+ sdk.cancel(order['oid'], order['coin'])
555
+ except HyperliquidError as e:
556
+ failures.append({'oid': order['oid'], 'error': str(e)})
557
+
558
+ if failures:
559
+ print(f"Failed to cancel {len(failures)} orders: {failures}")
560
+ ```
561
+
562
+ ### Resilient Order Placement
563
+
564
+ Use client order IDs (CLOIDs) for idempotent orders and categorize errors for retry logic:
565
+
566
+ ```python
567
+ import uuid
568
+ import time
569
+ import random
570
+ from hyperliquid_sdk import (
571
+ Order, HyperliquidError, RateLimitError, InvalidNonceError,
572
+ DuplicateOrderError, GeoBlockedError, InsufficientMarginError,
573
+ ValidationError, SignatureError, MaxOrdersError,
574
+ )
575
+
576
+ # Set a CLOID for idempotency — the exchange rejects duplicates
577
+ cloid = "0x" + uuid.uuid4().hex
578
+ order = sdk.order(Order.buy("BTC").size(0.001).price(65000).gtc().cloid(cloid))
579
+
580
+ # Error categories:
581
+ # Transient (retry): RateLimitError, InvalidNonceError
582
+ # Permanent (fail): GeoBlockedError, InsufficientMarginError, ValidationError,
583
+ # SignatureError, MaxOrdersError
584
+ # Already done: DuplicateOrderError (order already placed)
585
+
586
+ TRANSIENT_ERRORS = (RateLimitError, InvalidNonceError)
587
+
588
+ def place_with_retry(sdk, order_builder, max_retries=3):
589
+ """Place an order with exponential backoff and idempotency."""
590
+ cloid = "0x" + uuid.uuid4().hex
591
+ order_builder = order_builder.cloid(cloid)
592
+
593
+ for attempt in range(max_retries):
594
+ try:
595
+ return sdk.order(order_builder)
596
+ except DuplicateOrderError:
597
+ return None # Order already went through
598
+ except TRANSIENT_ERRORS as e:
599
+ if attempt == max_retries - 1:
600
+ raise
601
+ wait = (2 ** attempt) + random.random()
602
+ time.sleep(wait)
603
+
604
+ # Timeout configuration on SDK constructor
605
+ from hyperliquid_sdk import HyperliquidSDK
606
+ sdk = HyperliquidSDK(endpoint, private_key="0x...", timeout=30)
607
+ ```
608
+
432
609
  ### Leverage & Margin
433
610
 
434
611
  ```python
@@ -504,13 +681,15 @@ sdk.vault_withdraw(vault_address=HLP_VAULT, amount=50)
504
681
  ### Staking
505
682
 
506
683
  ```python
507
- # Stake/unstake HYPE
508
- sdk.stake(amount=1000)
509
- sdk.unstake(amount=500) # 7-day queue
684
+ # Move spot HYPE into undelegated staking HYPE.
685
+ # This is the balance Hyperliquid uses for order priority fees.
686
+ sdk.fund_priority_fees(0.001)
687
+ sdk.stake(amount=0.001)
688
+ sdk.unstake(amount=0.001) # 7-day queue
510
689
 
511
690
  # Delegate to validators
512
- sdk.delegate(validator="0x...", amount=500)
513
- sdk.undelegate(validator="0x...", amount=250)
691
+ sdk.delegate(validator="0x...", amount=0.5)
692
+ sdk.undelegate(validator="0x...", amount=0.25)
514
693
  ```
515
694
 
516
695
  ### Fluent Order Builder
@@ -525,6 +704,13 @@ order = sdk.order(
525
704
  .gtc()
526
705
  .reduce_only()
527
706
  )
707
+
708
+ priority_order = sdk.order(
709
+ Order.buy("HYPE")
710
+ .size(0.3)
711
+ .market()
712
+ .priority_fee(10000)
713
+ )
528
714
  ```
529
715
 
530
716
  ---
@@ -589,13 +775,13 @@ HyperliquidSDK(
589
775
  timeout=30, # Request timeout in seconds
590
776
  )
591
777
 
592
- # Access sub-clients
593
- sdk.info() # Info API (market data, user data, metadata)
594
- sdk.core() # HyperCore (blocks, trades, orders)
595
- sdk.evm() # EVM (Ethereum JSON-RPC)
596
- sdk.stream() # WebSocket streaming
597
- sdk.grpc() # gRPC streaming
598
- sdk.evm_stream() # EVM WebSocket (eth_subscribe)
778
+ # Access sub-clients (properties, not methods — no parentheses needed)
779
+ sdk.info # Info API (market data, user data, metadata)
780
+ sdk.core # HyperCore (blocks, trades, orders)
781
+ sdk.evm # EVM (Ethereum JSON-RPC)
782
+ sdk.stream # WebSocket streaming
783
+ sdk.grpc # gRPC streaming
784
+ sdk.evm_stream # EVM WebSocket (eth_subscribe)
599
785
  ```
600
786
 
601
787
  ---