hyperliquid-cli-python 0.1.0__py3-none-any.whl
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.
- hl_cli/__init__.py +1 -0
- hl_cli/cli/__init__.py +1 -0
- hl_cli/cli/argparse_main.py +814 -0
- hl_cli/cli/markets_tui.py +399 -0
- hl_cli/cli/runtime.py +82 -0
- hl_cli/commands/__init__.py +1 -0
- hl_cli/commands/app.py +1081 -0
- hl_cli/commands/order.py +918 -0
- hl_cli/core/__init__.py +1 -0
- hl_cli/core/context.py +156 -0
- hl_cli/core/order_config.py +23 -0
- hl_cli/infra/__init__.py +1 -0
- hl_cli/infra/db.py +277 -0
- hl_cli/infra/paths.py +5 -0
- hl_cli/utils/__init__.py +1 -0
- hl_cli/utils/market_table.py +66 -0
- hl_cli/utils/output.py +476 -0
- hl_cli/utils/validators.py +45 -0
- hl_cli/utils/watch.py +28 -0
- hyperliquid_cli_python-0.1.0.dist-info/METADATA +269 -0
- hyperliquid_cli_python-0.1.0.dist-info/RECORD +25 -0
- hyperliquid_cli_python-0.1.0.dist-info/WHEEL +5 -0
- hyperliquid_cli_python-0.1.0.dist-info/entry_points.txt +2 -0
- hyperliquid_cli_python-0.1.0.dist-info/licenses/LICENSE +32 -0
- hyperliquid_cli_python-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hyperliquid-cli-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python CLI for Hyperliquid DEX
|
|
5
|
+
Author: hyperliquid-cli contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: rich>=13.7.1
|
|
11
|
+
Requires-Dist: hyperliquid-python-sdk>=0.18.0
|
|
12
|
+
Requires-Dist: eth-account>=0.13.4
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Hyperliquid CLI (Python)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd hl
|
|
21
|
+
make install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
After installation, the `hl` command is available:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
hl --help
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Manual install is still available:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install .
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Bash Completion
|
|
37
|
+
|
|
38
|
+
`hl` can print a Bash completion script for top-level commands and subcommands.
|
|
39
|
+
|
|
40
|
+
`make install` installs the package and appends a managed completion line to
|
|
41
|
+
`~/.bashrc` if it is not already present.
|
|
42
|
+
|
|
43
|
+
Enable it for the current shell:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
eval "$(hl completion bash)"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Persist it in `~/.bashrc`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
echo 'eval "$(hl completion bash)"' >> ~/.bashrc
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`make uninstall` removes the managed completion line from `~/.bashrc`.
|
|
56
|
+
|
|
57
|
+
`pip install .` alone still does not edit shell startup files automatically.
|
|
58
|
+
|
|
59
|
+
To remove both the package and the managed `~/.bashrc` completion line:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
make uninstall
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Global Options
|
|
66
|
+
|
|
67
|
+
- `--json` Output JSON
|
|
68
|
+
- `--testnet` Use testnet
|
|
69
|
+
|
|
70
|
+
## Supported Commands
|
|
71
|
+
|
|
72
|
+
- `hl account add|ls|set-default|remove`
|
|
73
|
+
- `hl account positions|orders|balances|portfolio`
|
|
74
|
+
- `hl order ls|limit|market|tpsl|twap|twap-cancel|cancel|cancel-all|set-leverage|configure`
|
|
75
|
+
- `hl asset price|book|leverage`
|
|
76
|
+
- `hl markets ls|search`
|
|
77
|
+
- `hl referral set|status`
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
- DB: `~/.hl/hl.db`
|
|
82
|
+
- Order config: `~/.hl/order-config.json`
|
|
83
|
+
|
|
84
|
+
Environment variable fallback (when DB account is not configured):
|
|
85
|
+
|
|
86
|
+
- `HYPERLIQUID_PRIVATE_KEY`
|
|
87
|
+
- `HYPERLIQUID_WALLET_ADDRESS`
|
|
88
|
+
|
|
89
|
+
## Security Notes
|
|
90
|
+
|
|
91
|
+
Account data stored in `~/.hl/hl.db` is encrypted at rest for these fields:
|
|
92
|
+
|
|
93
|
+
- `user_address`
|
|
94
|
+
- `api_wallet_public_key`
|
|
95
|
+
- `api_wallet_private_key`
|
|
96
|
+
|
|
97
|
+
The current implementation derives a 32-byte key as follows:
|
|
98
|
+
|
|
99
|
+
1. Resolve the command path used to run `hl`
|
|
100
|
+
2. Hash that path with SHA-256
|
|
101
|
+
3. Use the resulting digest as the ChaCha20 key
|
|
102
|
+
|
|
103
|
+
Each stored value is encrypted independently with its own random nonce.
|
|
104
|
+
|
|
105
|
+
This means:
|
|
106
|
+
|
|
107
|
+
- the same installed command path can transparently decrypt the saved values
|
|
108
|
+
- changing the executable path can make existing saved account data undecryptable
|
|
109
|
+
- this is path-bound encryption, not password-based encryption
|
|
110
|
+
|
|
111
|
+
Example:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
$ which hl
|
|
115
|
+
/home/haturatu/.local/bin/hl
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
If `hl` is installed at a user-local path like `/home/haturatu/.local/bin/hl`, then
|
|
119
|
+
the encryption key is effectively tied to that installed command path. In normal usage,
|
|
120
|
+
that often behaves like "the user who has this `hl` on their path can decrypt the DB".
|
|
121
|
+
So in practice it can look close to per-user decryption when each user has their own
|
|
122
|
+
home directory and their own local install path.
|
|
123
|
+
|
|
124
|
+
Important limitation:
|
|
125
|
+
|
|
126
|
+
- this mechanism does **not** prove OS user identity by itself
|
|
127
|
+
- if another OS user can both read `~/.hl/hl.db` and execute the same `hl` binary
|
|
128
|
+
path, path-based derivation alone does not prevent that user from decrypting the data
|
|
129
|
+
|
|
130
|
+
So this mechanism is mainly useful as a coupling between the saved DB contents and the
|
|
131
|
+
specific installed command path. It helps prevent casual reuse of the DB from a different
|
|
132
|
+
binary location, but it is not a substitute for filesystem permissions or disk encryption.
|
|
133
|
+
|
|
134
|
+
Environment variable fallback still exists when DB account data is not configured:
|
|
135
|
+
|
|
136
|
+
- `HYPERLIQUID_PRIVATE_KEY`
|
|
137
|
+
- `HYPERLIQUID_WALLET_ADDRESS`
|
|
138
|
+
|
|
139
|
+
These environment variables are not stored in the encrypted DB. They are read as
|
|
140
|
+
plain process environment values at runtime.
|
|
141
|
+
|
|
142
|
+
Practical guidance:
|
|
143
|
+
|
|
144
|
+
- Use wallets or API keys that would not be catastrophic if leaked
|
|
145
|
+
- Restrict which OS user can run this tool
|
|
146
|
+
- If you need stronger protection, use disk encryption as the higher-level control
|
|
147
|
+
|
|
148
|
+
## Run for Development
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
cd hl
|
|
152
|
+
PYTHONPATH=src python -m hl_cli.cli.argparse_main --help
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## JSON Pattern Tests
|
|
156
|
+
|
|
157
|
+
`tests/` validates that every subcommand pattern produces parseable raw JSON output in `--json` mode.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
cd hl
|
|
161
|
+
PYTHONPATH=src python -m unittest -v tests.test_json_patterns
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## TWAP Orders
|
|
165
|
+
|
|
166
|
+
`hyperliquid-python-sdk` does not provide a high-level TWAP method, so this CLI signs and submits the official
|
|
167
|
+
`exchange` actions `twapOrder` / `twapCancel`.
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# 30-minute native TWAP
|
|
171
|
+
hl order twap buy 1.0 BTC 30
|
|
172
|
+
|
|
173
|
+
# Derive total TWAP size from USD margin (stake * leverage)
|
|
174
|
+
hl order twap buy 0 BTC 30 --stake 5
|
|
175
|
+
|
|
176
|
+
# Compatibility format: 5,10 is sent as total 50 minutes
|
|
177
|
+
hl order twap sell 2.0 ETH 5,10 --randomize
|
|
178
|
+
|
|
179
|
+
# Cancel TWAP
|
|
180
|
+
hl order twap-cancel BTC 12345
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Stake-Based Orders
|
|
184
|
+
|
|
185
|
+
`--stake` is used by the CLI to derive order size.
|
|
186
|
+
|
|
187
|
+
- If you pass `--stake 50 --leverage 20`, the CLI derives size from about `$1000`
|
|
188
|
+
of notional (`50 * 20`).
|
|
189
|
+
- If you pass `--stake 50` without `--leverage`, the CLI derives size from about
|
|
190
|
+
`$50` of notional.
|
|
191
|
+
|
|
192
|
+
Important: omitting `--leverage` does **not** mean your account or position is forced
|
|
193
|
+
to `1x`. It only means the CLI does not multiply `--stake` by leverage when calculating
|
|
194
|
+
the order size. If the exchange/account already has leverage set for that asset, the
|
|
195
|
+
resulting position can still show that existing leverage in `hl account positions`.
|
|
196
|
+
|
|
197
|
+
This means:
|
|
198
|
+
|
|
199
|
+
- `--stake 50` means the CLI sizes the order from about `$50` of notional
|
|
200
|
+
- `--stake 50 --leverage 20` means about `$1000` of position notional
|
|
201
|
+
|
|
202
|
+
So:
|
|
203
|
+
|
|
204
|
+
- `--leverage` changes how `--stake` is converted into order size
|
|
205
|
+
- existing leverage on the exchange can still affect margin usage and the leverage
|
|
206
|
+
shown later in `hl account positions`
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# No --leverage: CLI sizes the order from about $50 of BTC notional
|
|
210
|
+
hl order market buy BTC --stake 50
|
|
211
|
+
|
|
212
|
+
# No --leverage: CLI sizes the order from about $50 of ETH notional
|
|
213
|
+
hl order market buy ETH --stake 50
|
|
214
|
+
|
|
215
|
+
# With --leverage 20: CLI sizes the order from about $1,000 of BTC notional
|
|
216
|
+
hl order limit buy BTC 65000 --stake 50 --leverage 20 --cross
|
|
217
|
+
|
|
218
|
+
# With --leverage 20: CLI sizes the order from about $1,000 of BTC notional
|
|
219
|
+
hl order market buy BTC --stake 50 --leverage 20 --isolated
|
|
220
|
+
|
|
221
|
+
# Example:
|
|
222
|
+
# BTC at 69,000
|
|
223
|
+
# - --stake 50 => about 0.000724 BTC of order size
|
|
224
|
+
# - --stake 50 --leverage 20 => about 0.01449 BTC
|
|
225
|
+
#
|
|
226
|
+
# ETH at 2,020
|
|
227
|
+
# - --stake 50 => about 0.02475 ETH of order size
|
|
228
|
+
# - --stake 50 --leverage 20 => about 0.2475 ETH
|
|
229
|
+
|
|
230
|
+
# Set leverage and margin mode at order time
|
|
231
|
+
hl order limit buy BTC 65000 --stake 50 --leverage 20 --cross
|
|
232
|
+
hl order market buy BTC --stake 50 --leverage 20 --isolated
|
|
233
|
+
|
|
234
|
+
# Set leverage directly
|
|
235
|
+
hl order set-leverage BTC 20 --cross
|
|
236
|
+
|
|
237
|
+
# If leverage is invalid, show warning and retry with coin maxLeverage from /info type=meta
|
|
238
|
+
hl order set-leverage BTC 60
|
|
239
|
+
|
|
240
|
+
# Close full position by coin
|
|
241
|
+
hl order market close ETH
|
|
242
|
+
hl order market close xyz:TSLA
|
|
243
|
+
|
|
244
|
+
# Close 50% of a position
|
|
245
|
+
hl order market close ETH --ratio 0.5
|
|
246
|
+
|
|
247
|
+
# Set TP/SL trigger orders for an open position
|
|
248
|
+
hl order tpsl ETH --tp 1900 --sl 1800
|
|
249
|
+
hl order tpsl ETH --sl 1800 --ratio 0.5
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Acknowledgments
|
|
253
|
+
|
|
254
|
+
- https://app.hyperliquid.xyz/
|
|
255
|
+
- https://github.com/chrisling-dev/hyperliquid-cli
|
|
256
|
+
- https://github.com/ehfuzzz/hyperliquid-CLI
|
|
257
|
+
|
|
258
|
+
This project is primarily a Python implementation of
|
|
259
|
+
https://github.com/chrisling-dev/hyperliquid-cli.
|
|
260
|
+
Some features, including the TWAP order implementation, are also based on ideas from
|
|
261
|
+
https://github.com/ehfuzzz/hyperliquid-CLI.
|
|
262
|
+
|
|
263
|
+
This repository also includes changes such as expanded `order` subcommands, the
|
|
264
|
+
`--stake` option, and additional `market` subcommand functionality.
|
|
265
|
+
|
|
266
|
+
At the moment, I am not fully sure how this should be handled from a licensing and
|
|
267
|
+
attribution perspective, so this repository is being published under my BSD 3-Clause
|
|
268
|
+
License as a temporary choice. If you have a better idea for the appropriate license
|
|
269
|
+
notice or attribution, please open an issue.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
hl_cli/__init__.py,sha256=bJB1Z_wpf672ABdQVD5JqVOz1H-VIinI1LmyC9I0haI,38
|
|
2
|
+
hl_cli/cli/__init__.py,sha256=0v5LgBUFK9Sv9Xksq5llyygc1s0qDKMul3wtenezKns,43
|
|
3
|
+
hl_cli/cli/argparse_main.py,sha256=PEE8s25qVQIlhrOD40zjIErypym8gK-1VORKZT5vjdQ,30405
|
|
4
|
+
hl_cli/cli/markets_tui.py,sha256=OfGwbIU_SoA8zUwjRrm8Xe6AdZYbftWjFzHwOouhcmA,13046
|
|
5
|
+
hl_cli/cli/runtime.py,sha256=cy7ESOsWCUIXzFCJNHI4OsZMqUhXBwJ_0BBISWgJW78,2085
|
|
6
|
+
hl_cli/commands/__init__.py,sha256=P8lZ_2wMBwhuqPm8wE-xuPydwT4JWWPQ2W09PZLVxE0,31
|
|
7
|
+
hl_cli/commands/app.py,sha256=_JzC1wJL3MmjBoZ4AbdZakL4sIHCKXvLzC-MmvQLsTQ,36328
|
|
8
|
+
hl_cli/commands/order.py,sha256=mSO7fYWUS44H1iD1_xuo--wPJDXKa9mJvFAqmo0XAa8,29726
|
|
9
|
+
hl_cli/core/__init__.py,sha256=jnzp3snw1CCFRBaqfFMCn_zSloV7O3aT9ZwnF3hIT40,33
|
|
10
|
+
hl_cli/core/context.py,sha256=nuMnzcBS1WeKpevOvWc0iLGGFsYrxU6VjWq3M0sr_fU,5396
|
|
11
|
+
hl_cli/core/order_config.py,sha256=SP_M3jMUq0kb-atT4cgEh5M2RcpkQ3UNdtm59bVbcPc,604
|
|
12
|
+
hl_cli/infra/__init__.py,sha256=lL6lKVaAUaEsRHpMqEET-ZgMXrDX9vJ2FwnyNSmSB5c,47
|
|
13
|
+
hl_cli/infra/db.py,sha256=kK1A9DAVRpn2Cg4cg_N3Ttrh_bA3WQkkx5QpdNzbn7c,9321
|
|
14
|
+
hl_cli/infra/paths.py,sha256=8K6QUg7bBzWaDdkrUOMHS3dGGxo1vExcVde_z_G57gc,131
|
|
15
|
+
hl_cli/utils/__init__.py,sha256=vTzpzAhwZwhp9xdzSN95SWmf02qgw7Asc0ULXG4aEok,23
|
|
16
|
+
hl_cli/utils/market_table.py,sha256=MrrcDdzUnnn65cm55kc6rYp76BGFAcIb3QlDVfXGZ7o,2099
|
|
17
|
+
hl_cli/utils/output.py,sha256=Q3jzCArvjjfcY92QvGZ-5Q9P74G-dUQ3TjrU2t_BDe0,15243
|
|
18
|
+
hl_cli/utils/validators.py,sha256=hJ1hQmajfceGl9DDv-WS2D_WbTxfGrWuvN7D0qhSB-Q,1271
|
|
19
|
+
hl_cli/utils/watch.py,sha256=WZHbQ1q0GVqDmQYutzPp8wMuxdKfq23ZvPJ8yUFjBT0,581
|
|
20
|
+
hyperliquid_cli_python-0.1.0.dist-info/licenses/LICENSE,sha256=v78TwQbwNwXwMPEbrZ2W0fK3RFScNu5lfjxKi7Ug7mk,1604
|
|
21
|
+
hyperliquid_cli_python-0.1.0.dist-info/METADATA,sha256=1gZ8WGwDiUwdBuqlYciAZPotpZkq-4P2OWyGTKKBwdQ,7945
|
|
22
|
+
hyperliquid_cli_python-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
23
|
+
hyperliquid_cli_python-0.1.0.dist-info/entry_points.txt,sha256=Og8LGmpVd-oTJ4Z2Ic5Z87JzcCSJRJ5urQTAdiDTuIM,53
|
|
24
|
+
hyperliquid_cli_python-0.1.0.dist-info/top_level.txt,sha256=Z59lGaZW-HWWilKpRriLr0dL9ZA-gDHvcCycQnHYgj0,7
|
|
25
|
+
hyperliquid_cli_python-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, haturau
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
|
|
30
|
+
Inspired by:
|
|
31
|
+
- https://github.com/chrisling-dev/hyperliquid-cli
|
|
32
|
+
- https://github.com/ehfuzzz/hyperliquid-CLI
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hl_cli
|