hyperliquid-trading 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.
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: hyperliquid-trading
3
+ Version: 0.1.0
4
+ Summary: Hyperliquid trading CLI tools
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: hyperliquid-python-sdk>=0.22.0
8
+ Requires-Dist: click>=8.1.0
9
+ Requires-Dist: rich>=13.0.0
10
+ Requires-Dist: python-dotenv>=1.0.0
11
+
12
+ ---
13
+ name: hyperliquid-trading
14
+ description: |
15
+ Hyperliquid DEX 命令行交易工具。当用户需要查询 Hyperliquid 市场数据、管理账户、执行交易操作、设置杠杆、转账提现、HYPE 质押时使用此技能。支持主网和测试网。TRIGGER when: 用户提及 Hyperliquid、HL、衍生品形式(美元、石油、黄金、股票)的价格、永续合约交易、加密货币交易 CLI、查询币价、下单交易、查看持仓、资金费率、HYPE 质押、验证者委托等。
16
+ category: finance
17
+ tags: [trading, dex, cli, api, derivatives, staking]
18
+ ---
19
+
20
+ # Hyperliquid Trading CLI
21
+
22
+ 基于 Python SDK 的 Hyperliquid DEX 命令行交易工具,提供完整的市场数据查询、账户管理和交易功能。
23
+
24
+ ## 安装方式
25
+
26
+ ### 方式一:在线安装(推荐)
27
+
28
+ ```bash
29
+ # 从 PyPI 安装
30
+ pip install hyperliquid-trading
31
+
32
+ # 或使用 uv
33
+ uv pip install hyperliquid-trading
34
+ ```
35
+
36
+ ### 方式二:源码安装
37
+
38
+ ```bash
39
+ # 克隆项目
40
+ git clone <repo-url>
41
+ cd hyperliquid-trading
42
+
43
+ # 安装依赖
44
+ uv sync
45
+
46
+ # 安装 hyperliquid-trading
47
+ uv pip install -e .
48
+ ```
49
+
50
+ ## 环境配置
51
+
52
+ ```bash
53
+ # 初始化配置(交互式)
54
+ hl init
55
+
56
+ # 或手动创建 .env
57
+ cp .env.example .env
58
+ ```
59
+
60
+ ## 配置说明
61
+
62
+ `.env` 文件必需配置:
63
+
64
+ ```env
65
+ HL_NETWORK=testnet # mainnet 或 testnet
66
+ HL_ACCOUNT_ADDRESS=0x... # 钱包地址
67
+ HL_SECRET_KEY=0x... # 私钥(交易必需)
68
+ HL_API_SECRET_KEY= # API钱包私钥(可选)
69
+ HL_LOG_LEVEL=INFO # 日志级别
70
+ ```
71
+
72
+ ## 多账号管理
73
+
74
+ 支持通过不同的 `.env` 文件管理多个账号,方便在测试网、主网、不同钱包之间切换。
75
+
76
+ ### 环境文件命名
77
+
78
+ ```
79
+ .env # 默认配置(当前使用)
80
+ .env.test # 测试网账号
81
+ .env.prod # 主网账号
82
+ .env.wallet1 # 钱包1
83
+ .env.wallet2 # 钱包2
84
+ ```
85
+
86
+ ### 切换账号
87
+
88
+ **方式一:指定环境文件 (-e)**
89
+
90
+ ```bash
91
+ # 使用测试网账号
92
+ hl -e .env.test account state
93
+
94
+ # 使用主网账号交易
95
+ hl -e .env.prod trade buy BTC 0.01 -p 65000
96
+
97
+ # 使用指定钱包
98
+ hl -e .env.wallet1 account orders
99
+ ```
100
+
101
+ ## 命令速查
102
+
103
+ ### 市场数据 (market)
104
+
105
+ ```bash
106
+ # 获取价格
107
+ hl market prices [COIN1] [COIN2]... [-n mainnet|testnet]
108
+
109
+ # 查看订单簿
110
+ hl market book <COIN> [-d 10] [-n testnet]
111
+
112
+ # 获取资产参数(含最大杠杆倍率,设置杠杆前可先查询)
113
+ hl market context [COIN...] [-n testnet]
114
+
115
+ # 获取资金费率
116
+ hl market funding <COIN> [-n testnet] [-l 10]
117
+
118
+ # 获取 K 线数据
119
+ hl market candles <COIN> [-i 1h] [-H 24 | -d 30] [-n mainnet]
120
+ ```
121
+
122
+ ### 账户信息 (account)
123
+
124
+ ```bash
125
+ # 账户状态(余额、持仓)
126
+ hl account state [-a <ADDRESS>]
127
+
128
+ # 未成交订单
129
+ hl account orders [-a <ADDRESS>]
130
+
131
+ # 成交历史
132
+ hl account fills [-a <ADDRESS>] [-l 20]
133
+
134
+ # 资金费用历史
135
+ hl account funding [-a <ADDRESS>] [-l 20]
136
+
137
+ # 质押奖励历史
138
+ hl account rewards [-a <ADDRESS>]
139
+ ```
140
+
141
+ ### 交易操作 (trade)
142
+
143
+ > **注意**:交易会使用该币种上次设置的杠杆倍率。如不确定当前杠杆,建议先执行 `hl leverage set <COIN> <VALUE>` 确认设置。
144
+
145
+ ```bash
146
+ # 买入限价单
147
+ hl trade buy <COIN> <SIZE> -p <PRICE> [--cloid <ID>]
148
+
149
+ # 买入市价单(跳过确认)
150
+ hl trade buy <COIN> <SIZE> -y
151
+
152
+ # 卖出限价单
153
+ hl trade sell <COIN> <SIZE> -p <PRICE> [--reduce-only]
154
+
155
+ # 卖出市价单
156
+ hl trade sell <COIN> <SIZE> [--reduce-only]
157
+
158
+ # 取消订单
159
+ hl trade cancel <COIN> <ORDER_ID>
160
+
161
+ # 取消所有订单(跳过确认)
162
+ hl trade cancel-all [-c <COIN>] -y
163
+
164
+ # 修改订单
165
+ hl trade modify <COIN> <ORDER_ID> <NEW_SIZE> <NEW_PRICE>
166
+
167
+ # 平仓
168
+ hl trade close <COIN>
169
+ ```
170
+
171
+ ### 杠杆管理 (leverage)
172
+
173
+ ```bash
174
+ # 设置杠杆
175
+ hl leverage set <COIN> <VALUE> [--cross]
176
+
177
+ # 调整逐仓保证金
178
+ hl leverage margin <COIN> <AMOUNT>
179
+ ```
180
+
181
+ ### 转账提现 (transfer)
182
+
183
+ ```bash
184
+ # 内部转账
185
+ hl transfer send <DESTINATION> <AMOUNT> [--token USDC]
186
+
187
+ # 跨链提现(跳过确认)
188
+ hl transfer withdraw <DESTINATION> <AMOUNT> -y
189
+ ```
190
+
191
+ ### 质押功能 (staking)
192
+
193
+ HYPE 代币质押相关命令,支持查询验证者、委托质押、解除质押等操作。
194
+
195
+ ```bash
196
+ # 查看质押摘要(已质押、待解除数量)
197
+ hl staking summary [-a <ADDRESS>]
198
+
199
+ # 查看验证者列表
200
+ hl staking validators [-l 30] [--sort stake|commission|name]
201
+
202
+ # 查看质押委托
203
+ hl staking delegations [-a <ADDRESS>]
204
+
205
+ # 查看质押奖励历史
206
+ hl staking rewards [-a <ADDRESS>] [-l 20]
207
+
208
+ # 查看质押历史(委托/解除委托记录)
209
+ hl staking history [-a <ADDRESS>] [-l 20]
210
+
211
+ # 质押 HYPE 到验证者(需要私钥)
212
+ hl staking delegate <VALIDATOR_ADDRESS> <AMOUNT> -y
213
+
214
+ # 解除质押(需要私钥)
215
+ hl staking undelegate <VALIDATOR_ADDRESS> <AMOUNT> -y
216
+ ```
217
+
218
+ ## 使用示例
219
+
220
+ ### 查询市场
221
+
222
+ ```bash
223
+ # 查询 BTC/ETH 价格
224
+ hl market prices BTC ETH -n mainnet
225
+
226
+ # 查询 所有价格(数据量过大,不建议使用)
227
+ hl market prices -n mainnet
228
+
229
+ # 查看 BTC 订单簿前 5 档
230
+ hl market book BTC -d 5 -n mainnet
231
+
232
+ # 查看 ETH 资金费率
233
+ hl market funding ETH -n mainnet -l 5
234
+
235
+ # 查看 BTC 最近 24 小时 1 小时 K 线
236
+ hl market candles BTC -i 1h -H 24 -n mainnet
237
+
238
+ # 查看 ETH 最近 30 天日 K 线
239
+ hl market candles ETH -i 1d -d 30 -n mainnet
240
+
241
+ # 查看 BTC 最近 1 年周 K 线
242
+ hl market candles BTC -i 1w -d 365 -n mainnet
243
+
244
+ # 查看 BTC 最近 1 年月 K 线
245
+ hl market candles BTC -i 1M -d 365 -n mainnet
246
+
247
+ # 查看 BTC 最近 1 年季度 K 线
248
+ hl market candles BTC -i 3M -d 365 -n mainnet
249
+
250
+ # 查看 BTC 最近 1 年半年 K 线
251
+ hl market candles BTC -i 6M -d 365 -n mainnet
252
+
253
+ # 查询 所有参数(数据量过大,不建议使用)
254
+ hl market prices -n mainnet
255
+
256
+ # 查询 BTC ETH 资产交易参数
257
+ hl market context BTC ETH -n mainnet
258
+
259
+ # 查询 所有可交易的资产交易参数(数据量过大,不建议使用)
260
+ hl market context -n mainnet
261
+
262
+
263
+ ```
264
+
265
+ ### 交易操作
266
+
267
+ ```bash
268
+ # 测试网买入 0.1 BTC 限价单 @ 65000
269
+ hl trade buy BTC 0.1 -p 65000
270
+
271
+ # 测试网市价卖出 0.05 ETH
272
+ hl trade sell ETH 0.05
273
+
274
+ # 设置 BTC 杠杆为 10x 全仓
275
+ hl leverage set BTC 10 --cross
276
+
277
+ # 平掉 BTC 仓位
278
+ hl trade close BTC
279
+ ```
280
+
281
+ ### 账户查询
282
+
283
+ ```bash
284
+ # 查看账户概览
285
+ hl account state
286
+
287
+ # 查看最近 10 笔成交
288
+ hl account fills -l 10
289
+
290
+ # 查看资金费用
291
+ hl account funding -l 20
292
+ ```
293
+
294
+ ### 质押操作
295
+
296
+ ```bash
297
+ # 查看质押摘要
298
+ hl staking summary
299
+
300
+ # 查看验证者列表(按质押量排序,显示前 10 个)
301
+ hl staking validators -l 10 --sort stake
302
+
303
+ # 查看验证者列表(按佣金率排序)
304
+ hl staking validators --sort commission
305
+
306
+ # 查看当前委托
307
+ hl staking delegations
308
+
309
+ # 查看质押奖励
310
+ hl staking rewards -l 10
311
+
312
+ # 质押 10 HYPE 到指定验证者
313
+ hl staking delegate 0x1234... 10 -y
314
+
315
+ # 解除 5 HYPE 质押
316
+ hl staking undelegate 0x1234... 5 -y
317
+ ```
318
+
319
+ ## 安全提示
320
+
321
+ 1. **密钥安全**: 永远不要直接读取配置文件
322
+ 2. **失败兜底**: 交易过程中发生异常最大重试次数不得超过3次,需告警用户协助排查解决
323
+ 3. **小额测试**: 首次使用建议先用小额测试
324
+
325
+ ## 常见问题
326
+
327
+ ### 网络选择
328
+
329
+ - `testnet`: 测试网,无风险,用于开发和测试
330
+ - `mainnet`: 主网,真实资金,谨慎操作
331
+
332
+ ### 订单类型
333
+
334
+ - 限价单: 指定价格,`-p <PRICE>`
335
+ - 市价单: 不指定价格,按最优价格成交
336
+ - Reduce-only: 只减仓,不开新仓
337
+
338
+ ### 全局选项
339
+
340
+ ```bash
341
+ # 指定环境文件
342
+ hl -e /path/to/.env <command>
343
+
344
+ # 启用详细日志
345
+ hl -v <command>
346
+
347
+ # 输出原始 JSON 格式(适用于 market/account 命令)
348
+ hl --json market prices BTC ETH
349
+ hl -j account state
350
+
351
+ # 跳过确认(适用于 trade/leverage/transfer 命令)
352
+ hl <command> -y
353
+ hl <command> --yes
354
+
355
+ # 查看版本
356
+ hl version
357
+ ```
358
+
359
+ > **JSON 输出结构文档**: [references/output_json_schema.md](references/output_json_schema.md)
360
+
361
+ ## 项目结构
362
+
363
+ ```
364
+ hyperliquid-trading/
365
+ ├── scripts/
366
+ │ ├── cli.py # CLI 主程序
367
+ │ ├── config.py # 配置管理
368
+ │ └── hyperliquid_client.py # SDK 封装
369
+ ├── references/
370
+ │ └── output_json_schema.md # JSON 输出结构文档
371
+ ├── .env.example # 环境变量示例
372
+ ├── pyproject.toml # 项目配置
373
+ └── SKILL.md # 本文档
374
+ ```
375
+
376
+ ## 参考链接
377
+
378
+ - [Hyperliquid 官方文档](https://hyperliquid.gitbook.io/hyperliquid-docs/)
379
+ - [Python SDK GitHub](https://github.com/hyperliquid-dex/hyperliquid-python-sdk)