hyperliquid-sdk 0.1.0__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 (39) hide show
  1. hyperliquid_sdk-0.1.0/.gitignore +4 -0
  2. hyperliquid_sdk-0.1.0/LICENSE +21 -0
  3. hyperliquid_sdk-0.1.0/PKG-INFO +296 -0
  4. hyperliquid_sdk-0.1.0/README.md +261 -0
  5. hyperliquid_sdk-0.1.0/approve.py +18 -0
  6. hyperliquid_sdk-0.1.0/cancel_order.py +71 -0
  7. hyperliquid_sdk-0.1.0/check_status.py +7 -0
  8. hyperliquid_sdk-0.1.0/client.py +75 -0
  9. hyperliquid_sdk-0.1.0/close_position.py +31 -0
  10. hyperliquid_sdk-0.1.0/hip3_order.py +39 -0
  11. hyperliquid_sdk-0.1.0/hyperliquid_sdk/__init__.py +65 -0
  12. hyperliquid_sdk-0.1.0/hyperliquid_sdk/client.py +688 -0
  13. hyperliquid_sdk-0.1.0/hyperliquid_sdk/errors.py +143 -0
  14. hyperliquid_sdk-0.1.0/hyperliquid_sdk/order.py +339 -0
  15. hyperliquid_sdk-0.1.0/hyperliquid_sdk/py.typed +0 -0
  16. hyperliquid_sdk-0.1.0/list_markets.py +34 -0
  17. hyperliquid_sdk-0.1.0/market_order.py +35 -0
  18. hyperliquid_sdk-0.1.0/modify_order.py +81 -0
  19. hyperliquid_sdk-0.1.0/open_orders.py +21 -0
  20. hyperliquid_sdk-0.1.0/order_status.py +24 -0
  21. hyperliquid_sdk-0.1.0/place_order.py +39 -0
  22. hyperliquid_sdk-0.1.0/pyproject.toml +75 -0
  23. hyperliquid_sdk-0.1.0/requirements.txt +2 -0
  24. hyperliquid_sdk-0.1.0/revoke.py +16 -0
  25. hyperliquid_sdk-0.1.0/roundtrip.py +64 -0
  26. hyperliquid_sdk-0.1.0/sdk_examples/README.md +116 -0
  27. hyperliquid_sdk-0.1.0/sdk_examples/__init__.py +1 -0
  28. hyperliquid_sdk-0.1.0/sdk_examples/approve.py +15 -0
  29. hyperliquid_sdk-0.1.0/sdk_examples/cancel_all.py +13 -0
  30. hyperliquid_sdk-0.1.0/sdk_examples/cancel_order.py +20 -0
  31. hyperliquid_sdk-0.1.0/sdk_examples/close_position.py +13 -0
  32. hyperliquid_sdk-0.1.0/sdk_examples/fluent_builder.py +47 -0
  33. hyperliquid_sdk-0.1.0/sdk_examples/full_demo.py +102 -0
  34. hyperliquid_sdk-0.1.0/sdk_examples/hip3_order.py +16 -0
  35. hyperliquid_sdk-0.1.0/sdk_examples/market_order.py +13 -0
  36. hyperliquid_sdk-0.1.0/sdk_examples/modify_order.py +22 -0
  37. hyperliquid_sdk-0.1.0/sdk_examples/open_orders.py +17 -0
  38. hyperliquid_sdk-0.1.0/sdk_examples/place_order.py +13 -0
  39. hyperliquid_sdk-0.1.0/sdk_examples/roundtrip.py +21 -0
@@ -0,0 +1,4 @@
1
+ rust/target/
2
+ typescript/node_modules/
3
+ python/__pycache__/
4
+ .env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QuickNode, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,296 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperliquid-sdk
3
+ Version: 0.1.0
4
+ Summary: The simplest way to trade on Hyperliquid. One line to place orders, zero ceremony.
5
+ Project-URL: Homepage, https://hyperliquidapi.com
6
+ Project-URL: Documentation, https://hyperliquidapi.com/docs
7
+ Project-URL: Repository, https://github.com/quiknode-labs/hyperliquid-sdk-python
8
+ Project-URL: Changelog, https://github.com/quiknode-labs/hyperliquid-sdk-python/releases
9
+ Author-email: Mauro Delazeri <mauro@quicknode.com>, QuickNode <support@quicknode.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,crypto,defi,hyperliquid,perpetuals,perps,sdk,trading
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Office/Business :: Financial :: Investment
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.9
26
+ Requires-Dist: eth-account>=0.10.0
27
+ Requires-Dist: requests>=2.28.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: black>=23.0.0; extra == 'dev'
30
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
32
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Hyperliquid SDK
37
+
38
+ **The simplest way to trade on Hyperliquid.** One line to place orders, zero ceremony.
39
+
40
+ ```python
41
+ from hyperliquid_sdk import HyperliquidSDK
42
+
43
+ sdk = HyperliquidSDK()
44
+ order = sdk.market_buy("BTC", notional=100) # Buy $100 of BTC
45
+ ```
46
+
47
+ That's it. No build-sign-send ceremony. No manual hash signing. No nonce tracking. Just trading.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install hyperliquid-sdk
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ### 1. Set your private key
58
+
59
+ ```bash
60
+ export PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
61
+ ```
62
+
63
+ ### 2. Start trading
64
+
65
+ ```python
66
+ from hyperliquid_sdk import HyperliquidSDK
67
+
68
+ sdk = HyperliquidSDK()
69
+
70
+ # Market orders
71
+ order = sdk.market_buy("BTC", size=0.001)
72
+ order = sdk.market_sell("ETH", notional=100) # $100 worth
73
+
74
+ # Limit orders
75
+ order = sdk.buy("BTC", size=0.001, price=65000, tif="gtc")
76
+
77
+ # Check your order
78
+ print(order.status) # "filled" or "resting"
79
+ print(order.oid) # Order ID
80
+ ```
81
+
82
+ ## Features
83
+
84
+ ### One-Line Orders
85
+
86
+ ```python
87
+ # Market orders - execute immediately
88
+ sdk.market_buy("BTC", size=0.001)
89
+ sdk.market_sell("ETH", notional=100)
90
+
91
+ # Limit orders
92
+ sdk.buy("BTC", size=0.001, price=65000)
93
+ sdk.sell("ETH", size=0.5, price=4000, tif="gtc")
94
+
95
+ # Perp trader aliases
96
+ sdk.long("BTC", size=0.001, price=65000)
97
+ sdk.short("ETH", notional=500, tif="ioc")
98
+ ```
99
+
100
+ ### Order Management
101
+
102
+ ```python
103
+ # Place a resting order
104
+ order = sdk.buy("BTC", size=0.001, price=60000, tif="gtc")
105
+
106
+ # Modify it
107
+ order.modify(price=61000)
108
+
109
+ # Cancel it
110
+ order.cancel()
111
+
112
+ # Cancel all orders
113
+ sdk.cancel_all()
114
+ sdk.cancel_all("BTC") # Just BTC orders
115
+ ```
116
+
117
+ ### Position Management
118
+
119
+ ```python
120
+ # Close a position completely (SDK figures out size and direction)
121
+ sdk.close_position("BTC")
122
+ ```
123
+
124
+ ### Fluent Order Builder
125
+
126
+ For power users who want maximum control:
127
+
128
+ ```python
129
+ from hyperliquid_sdk import Order
130
+
131
+ order = sdk.order(
132
+ Order.buy("BTC")
133
+ .size(0.001)
134
+ .price(65000)
135
+ .gtc()
136
+ .reduce_only()
137
+ )
138
+ ```
139
+
140
+ ### HIP-3 Markets
141
+
142
+ Trade HIP-3 markets (like Hypersea) with the same API:
143
+
144
+ ```python
145
+ sdk.buy("xyz:SILVER", notional=100, tif="ioc")
146
+ ```
147
+
148
+ ### Market Data
149
+
150
+ ```python
151
+ # Get mid price
152
+ mid = sdk.get_mid("BTC")
153
+
154
+ # List all markets
155
+ markets = sdk.markets()
156
+
157
+ # View open orders
158
+ orders = sdk.open_orders()
159
+ ```
160
+
161
+ ## Error Handling
162
+
163
+ Clear, actionable errors with guidance:
164
+
165
+ ```python
166
+ from hyperliquid_sdk import (
167
+ HyperliquidSDK,
168
+ ApprovalError,
169
+ ValidationError,
170
+ GeoBlockedError,
171
+ )
172
+
173
+ try:
174
+ order = sdk.buy("BTC", size=0.001, price=65000)
175
+ except ApprovalError as e:
176
+ print(f"Need approval: {e.guidance}")
177
+ sdk.approve_builder_fee("1%")
178
+ except ValidationError as e:
179
+ print(f"Invalid order: {e.message}")
180
+ except GeoBlockedError as e:
181
+ print(f"Access denied: {e.guidance}")
182
+ ```
183
+
184
+ ## Auto-Approval
185
+
186
+ Skip the approval step entirely:
187
+
188
+ ```python
189
+ sdk = HyperliquidSDK(auto_approve=True)
190
+ # Now just trade - approval happens automatically
191
+ ```
192
+
193
+ ## API Reference
194
+
195
+ ### HyperliquidSDK
196
+
197
+ ```python
198
+ HyperliquidSDK(
199
+ private_key=None, # Falls back to PRIVATE_KEY env var
200
+ auto_approve=False, # Auto-approve builder fee
201
+ max_fee="1%", # Max fee for auto-approval
202
+ )
203
+ ```
204
+
205
+ ### Order Methods
206
+
207
+ | Method | Description |
208
+ |--------|-------------|
209
+ | `buy(asset, size=, price=, tif=)` | Place a buy order |
210
+ | `sell(asset, size=, price=, tif=)` | Place a sell order |
211
+ | `market_buy(asset, size=)` | Market buy |
212
+ | `market_sell(asset, size=)` | Market sell |
213
+ | `long(asset, ...)` | Alias for buy |
214
+ | `short(asset, ...)` | Alias for sell |
215
+
216
+ ### Order Parameters
217
+
218
+ | Parameter | Type | Description |
219
+ |-----------|------|-------------|
220
+ | `asset` | str | Asset name ("BTC", "ETH", "xyz:SILVER") |
221
+ | `size` | float | Size in asset units |
222
+ | `notional` | float | Size in USD (alternative to size) |
223
+ | `price` | float | Limit price |
224
+ | `tif` | str | Time in force: "ioc", "gtc", "alo", "market" |
225
+ | `reduce_only` | bool | Close position only |
226
+
227
+ ### Management Methods
228
+
229
+ | Method | Description |
230
+ |--------|-------------|
231
+ | `cancel(oid)` | Cancel order by ID |
232
+ | `cancel_all(asset=None)` | Cancel all orders |
233
+ | `close_position(asset)` | Close a position |
234
+ | `modify(oid, price=, size=)` | Modify an order |
235
+
236
+ ### Query Methods
237
+
238
+ | Method | Description |
239
+ |--------|-------------|
240
+ | `get_mid(asset)` | Get mid price |
241
+ | `markets()` | List all markets |
242
+ | `open_orders()` | Get open orders |
243
+ | `order_status(oid)` | Get order status |
244
+ | `approval_status()` | Check builder fee approval |
245
+
246
+ ### PlacedOrder Object
247
+
248
+ ```python
249
+ order = sdk.buy("BTC", size=0.001, price=65000, tif="gtc")
250
+
251
+ order.oid # Order ID
252
+ order.status # "filled", "resting", "error: ..."
253
+ order.asset # "BTC"
254
+ order.side # "buy" or "sell"
255
+ order.size # "0.001"
256
+ order.price # "65000"
257
+ order.filled_size # Filled amount (if filled)
258
+ order.is_filled # True if filled
259
+ order.is_resting # True if resting
260
+
261
+ order.cancel() # Cancel this order
262
+ order.modify(price=66000) # Modify this order
263
+ ```
264
+
265
+ ## Examples
266
+
267
+ See the [examples](./sdk_examples/) directory for complete working examples:
268
+
269
+ - `market_order.py` - Market order in 5 lines
270
+ - `place_order.py` - Limit order
271
+ - `roundtrip.py` - Buy then sell
272
+ - `cancel_order.py` - Place and cancel
273
+ - `modify_order.py` - Place and modify
274
+ - `close_position.py` - Close a position
275
+ - `fluent_builder.py` - Power user patterns
276
+ - `full_demo.py` - All features
277
+
278
+ ## Compared to Raw API
279
+
280
+ | Operation | Raw API | SDK | Reduction |
281
+ |-----------|---------|-----|-----------|
282
+ | Market order | 35 lines | 1 line | 97% |
283
+ | Limit order | 39 lines | 1 line | 97% |
284
+ | Cancel order | 71 lines | 2 lines | 97% |
285
+ | Roundtrip | 64 lines | 4 lines | 94% |
286
+
287
+ ## Links
288
+
289
+ - **Website**: https://hyperliquidapi.com
290
+ - **Documentation**: https://hyperliquidapi.com/docs
291
+ - **Approval Page**: https://hyperliquidapi.com/approve
292
+ - **GitHub**: https://github.com/quiknode-labs/hyperliquid-sdk-python
293
+
294
+ ## License
295
+
296
+ MIT License - see [LICENSE](LICENSE) for details.
@@ -0,0 +1,261 @@
1
+ # Hyperliquid SDK
2
+
3
+ **The simplest way to trade on Hyperliquid.** One line to place orders, zero ceremony.
4
+
5
+ ```python
6
+ from hyperliquid_sdk import HyperliquidSDK
7
+
8
+ sdk = HyperliquidSDK()
9
+ order = sdk.market_buy("BTC", notional=100) # Buy $100 of BTC
10
+ ```
11
+
12
+ That's it. No build-sign-send ceremony. No manual hash signing. No nonce tracking. Just trading.
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ pip install hyperliquid-sdk
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Set your private key
23
+
24
+ ```bash
25
+ export PRIVATE_KEY="0xYOUR_PRIVATE_KEY"
26
+ ```
27
+
28
+ ### 2. Start trading
29
+
30
+ ```python
31
+ from hyperliquid_sdk import HyperliquidSDK
32
+
33
+ sdk = HyperliquidSDK()
34
+
35
+ # Market orders
36
+ order = sdk.market_buy("BTC", size=0.001)
37
+ order = sdk.market_sell("ETH", notional=100) # $100 worth
38
+
39
+ # Limit orders
40
+ order = sdk.buy("BTC", size=0.001, price=65000, tif="gtc")
41
+
42
+ # Check your order
43
+ print(order.status) # "filled" or "resting"
44
+ print(order.oid) # Order ID
45
+ ```
46
+
47
+ ## Features
48
+
49
+ ### One-Line Orders
50
+
51
+ ```python
52
+ # Market orders - execute immediately
53
+ sdk.market_buy("BTC", size=0.001)
54
+ sdk.market_sell("ETH", notional=100)
55
+
56
+ # Limit orders
57
+ sdk.buy("BTC", size=0.001, price=65000)
58
+ sdk.sell("ETH", size=0.5, price=4000, tif="gtc")
59
+
60
+ # Perp trader aliases
61
+ sdk.long("BTC", size=0.001, price=65000)
62
+ sdk.short("ETH", notional=500, tif="ioc")
63
+ ```
64
+
65
+ ### Order Management
66
+
67
+ ```python
68
+ # Place a resting order
69
+ order = sdk.buy("BTC", size=0.001, price=60000, tif="gtc")
70
+
71
+ # Modify it
72
+ order.modify(price=61000)
73
+
74
+ # Cancel it
75
+ order.cancel()
76
+
77
+ # Cancel all orders
78
+ sdk.cancel_all()
79
+ sdk.cancel_all("BTC") # Just BTC orders
80
+ ```
81
+
82
+ ### Position Management
83
+
84
+ ```python
85
+ # Close a position completely (SDK figures out size and direction)
86
+ sdk.close_position("BTC")
87
+ ```
88
+
89
+ ### Fluent Order Builder
90
+
91
+ For power users who want maximum control:
92
+
93
+ ```python
94
+ from hyperliquid_sdk import Order
95
+
96
+ order = sdk.order(
97
+ Order.buy("BTC")
98
+ .size(0.001)
99
+ .price(65000)
100
+ .gtc()
101
+ .reduce_only()
102
+ )
103
+ ```
104
+
105
+ ### HIP-3 Markets
106
+
107
+ Trade HIP-3 markets (like Hypersea) with the same API:
108
+
109
+ ```python
110
+ sdk.buy("xyz:SILVER", notional=100, tif="ioc")
111
+ ```
112
+
113
+ ### Market Data
114
+
115
+ ```python
116
+ # Get mid price
117
+ mid = sdk.get_mid("BTC")
118
+
119
+ # List all markets
120
+ markets = sdk.markets()
121
+
122
+ # View open orders
123
+ orders = sdk.open_orders()
124
+ ```
125
+
126
+ ## Error Handling
127
+
128
+ Clear, actionable errors with guidance:
129
+
130
+ ```python
131
+ from hyperliquid_sdk import (
132
+ HyperliquidSDK,
133
+ ApprovalError,
134
+ ValidationError,
135
+ GeoBlockedError,
136
+ )
137
+
138
+ try:
139
+ order = sdk.buy("BTC", size=0.001, price=65000)
140
+ except ApprovalError as e:
141
+ print(f"Need approval: {e.guidance}")
142
+ sdk.approve_builder_fee("1%")
143
+ except ValidationError as e:
144
+ print(f"Invalid order: {e.message}")
145
+ except GeoBlockedError as e:
146
+ print(f"Access denied: {e.guidance}")
147
+ ```
148
+
149
+ ## Auto-Approval
150
+
151
+ Skip the approval step entirely:
152
+
153
+ ```python
154
+ sdk = HyperliquidSDK(auto_approve=True)
155
+ # Now just trade - approval happens automatically
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### HyperliquidSDK
161
+
162
+ ```python
163
+ HyperliquidSDK(
164
+ private_key=None, # Falls back to PRIVATE_KEY env var
165
+ auto_approve=False, # Auto-approve builder fee
166
+ max_fee="1%", # Max fee for auto-approval
167
+ )
168
+ ```
169
+
170
+ ### Order Methods
171
+
172
+ | Method | Description |
173
+ |--------|-------------|
174
+ | `buy(asset, size=, price=, tif=)` | Place a buy order |
175
+ | `sell(asset, size=, price=, tif=)` | Place a sell order |
176
+ | `market_buy(asset, size=)` | Market buy |
177
+ | `market_sell(asset, size=)` | Market sell |
178
+ | `long(asset, ...)` | Alias for buy |
179
+ | `short(asset, ...)` | Alias for sell |
180
+
181
+ ### Order Parameters
182
+
183
+ | Parameter | Type | Description |
184
+ |-----------|------|-------------|
185
+ | `asset` | str | Asset name ("BTC", "ETH", "xyz:SILVER") |
186
+ | `size` | float | Size in asset units |
187
+ | `notional` | float | Size in USD (alternative to size) |
188
+ | `price` | float | Limit price |
189
+ | `tif` | str | Time in force: "ioc", "gtc", "alo", "market" |
190
+ | `reduce_only` | bool | Close position only |
191
+
192
+ ### Management Methods
193
+
194
+ | Method | Description |
195
+ |--------|-------------|
196
+ | `cancel(oid)` | Cancel order by ID |
197
+ | `cancel_all(asset=None)` | Cancel all orders |
198
+ | `close_position(asset)` | Close a position |
199
+ | `modify(oid, price=, size=)` | Modify an order |
200
+
201
+ ### Query Methods
202
+
203
+ | Method | Description |
204
+ |--------|-------------|
205
+ | `get_mid(asset)` | Get mid price |
206
+ | `markets()` | List all markets |
207
+ | `open_orders()` | Get open orders |
208
+ | `order_status(oid)` | Get order status |
209
+ | `approval_status()` | Check builder fee approval |
210
+
211
+ ### PlacedOrder Object
212
+
213
+ ```python
214
+ order = sdk.buy("BTC", size=0.001, price=65000, tif="gtc")
215
+
216
+ order.oid # Order ID
217
+ order.status # "filled", "resting", "error: ..."
218
+ order.asset # "BTC"
219
+ order.side # "buy" or "sell"
220
+ order.size # "0.001"
221
+ order.price # "65000"
222
+ order.filled_size # Filled amount (if filled)
223
+ order.is_filled # True if filled
224
+ order.is_resting # True if resting
225
+
226
+ order.cancel() # Cancel this order
227
+ order.modify(price=66000) # Modify this order
228
+ ```
229
+
230
+ ## Examples
231
+
232
+ See the [examples](./sdk_examples/) directory for complete working examples:
233
+
234
+ - `market_order.py` - Market order in 5 lines
235
+ - `place_order.py` - Limit order
236
+ - `roundtrip.py` - Buy then sell
237
+ - `cancel_order.py` - Place and cancel
238
+ - `modify_order.py` - Place and modify
239
+ - `close_position.py` - Close a position
240
+ - `fluent_builder.py` - Power user patterns
241
+ - `full_demo.py` - All features
242
+
243
+ ## Compared to Raw API
244
+
245
+ | Operation | Raw API | SDK | Reduction |
246
+ |-----------|---------|-----|-----------|
247
+ | Market order | 35 lines | 1 line | 97% |
248
+ | Limit order | 39 lines | 1 line | 97% |
249
+ | Cancel order | 71 lines | 2 lines | 97% |
250
+ | Roundtrip | 64 lines | 4 lines | 94% |
251
+
252
+ ## Links
253
+
254
+ - **Website**: https://hyperliquidapi.com
255
+ - **Documentation**: https://hyperliquidapi.com/docs
256
+ - **Approval Page**: https://hyperliquidapi.com/approve
257
+ - **GitHub**: https://github.com/quiknode-labs/hyperliquid-sdk-python
258
+
259
+ ## License
260
+
261
+ MIT License - see [LICENSE](LICENSE) for details.
@@ -0,0 +1,18 @@
1
+ """Approve builder fee (one-time setup)."""
2
+
3
+ from client import exchange, sign_hash
4
+
5
+ MAX_FEE = "1%"
6
+
7
+ res = exchange({
8
+ "action": {"type": "approveBuilderFee", "maxFeeRate": MAX_FEE},
9
+ })
10
+ sig = sign_hash(res["hash"])
11
+
12
+ exchange({
13
+ "action": {"type": "approveBuilderFee", "maxFeeRate": MAX_FEE},
14
+ "nonce": res["nonce"],
15
+ "signature": sig,
16
+ })
17
+
18
+ print("Builder fee approved.")
@@ -0,0 +1,71 @@
1
+ """Place a resting order (GTC, 3% below mid), then cancel it."""
2
+
3
+ import json
4
+ from client import exchange, sign_hash, get_mid
5
+
6
+ COIN = "BTC"
7
+
8
+ mid = get_mid(COIN)
9
+ if mid == 0:
10
+ print(f"Could not fetch {COIN} mid price")
11
+ raise SystemExit(1)
12
+
13
+ sz = round(11.0 / mid, 5)
14
+ rest_px = int(mid * 0.97)
15
+
16
+ print(f"{COIN} mid: ${mid:,.2f}")
17
+ print(f"Placing resting BUY {sz} @ {rest_px} (GTC, 3% below mid)\n")
18
+
19
+ res = exchange({
20
+ "action": {
21
+ "type": "order",
22
+ "orders": [{
23
+ "asset": COIN,
24
+ "side": "buy",
25
+ "price": str(rest_px),
26
+ "size": str(sz),
27
+ "tif": "gtc",
28
+ }],
29
+ },
30
+ })
31
+ sig = sign_hash(res["hash"])
32
+
33
+ result = exchange({
34
+ "action": res["action"],
35
+ "nonce": res["nonce"],
36
+ "signature": sig,
37
+ })
38
+
39
+ exchange_resp = result["exchangeResponse"]
40
+ statuses = exchange_resp.get("response", {}).get("data", {}).get("statuses", [])
41
+
42
+ oid = None
43
+ for s in statuses:
44
+ if isinstance(s, dict) and "resting" in s:
45
+ oid = s["resting"].get("oid")
46
+ break
47
+
48
+ if oid is None:
49
+ print("Could not extract OID from resting order")
50
+ print(json.dumps(exchange_resp, indent=2))
51
+ raise SystemExit(1)
52
+
53
+ print(f"Order resting (OID: {oid})")
54
+ print("Cancelling...\n")
55
+
56
+ cancel_action = {
57
+ "type": "cancel",
58
+ "cancels": [{"a": COIN, "o": oid}],
59
+ }
60
+
61
+ res = exchange({"action": cancel_action})
62
+ sig = sign_hash(res["hash"])
63
+
64
+ result = exchange({
65
+ "action": cancel_action,
66
+ "nonce": res["nonce"],
67
+ "signature": sig,
68
+ })
69
+
70
+ print(json.dumps(result["exchangeResponse"], indent=2))
71
+ print("\nOrder cancelled.")
@@ -0,0 +1,7 @@
1
+ """Check builder fee approval status."""
2
+
3
+ import json
4
+ from client import get_approval, address
5
+
6
+ res = get_approval(address)
7
+ print(json.dumps(res, indent=2))