@nktkas/hyperliquid 0.25.0-beta.2 → 0.25.0-beta.3

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 (220) hide show
  1. package/README.md +18 -2
  2. package/esm/bin/cli.d.ts +3 -0
  3. package/esm/bin/cli.d.ts.map +1 -0
  4. package/esm/bin/cli.js +452 -0
  5. package/esm/bin/cli.js.map +1 -0
  6. package/esm/src/{errors.d.ts → _errors.d.ts} +1 -1
  7. package/esm/src/_errors.d.ts.map +1 -0
  8. package/esm/src/{errors.js → _errors.js} +1 -1
  9. package/esm/src/_errors.js.map +1 -0
  10. package/esm/src/clients/exchange.d.ts +4 -4
  11. package/esm/src/clients/exchange.d.ts.map +1 -1
  12. package/esm/src/clients/exchange.js +4 -4
  13. package/esm/src/clients/exchange.js.map +1 -1
  14. package/esm/src/clients/info.d.ts +23 -1
  15. package/esm/src/clients/info.d.ts.map +1 -1
  16. package/esm/src/clients/info.js +27 -1
  17. package/esm/src/clients/info.js.map +1 -1
  18. package/esm/src/clients/multiSign.d.ts +1 -1
  19. package/esm/src/clients/multiSign.d.ts.map +1 -1
  20. package/esm/src/clients/multiSign.js +1 -1
  21. package/esm/src/clients/multiSign.js.map +1 -1
  22. package/esm/src/mod.d.ts +21 -0
  23. package/esm/src/mod.d.ts.map +1 -0
  24. package/esm/src/mod.js +14 -0
  25. package/esm/src/mod.js.map +1 -0
  26. package/esm/src/schemas/_base.d.ts +8 -4
  27. package/esm/src/schemas/_base.d.ts.map +1 -1
  28. package/esm/src/schemas/_base.js +27 -2
  29. package/esm/src/schemas/_base.js.map +1 -1
  30. package/esm/src/schemas/exchange/requests.d.ts +1598 -1598
  31. package/esm/src/schemas/exchange/requests.d.ts.map +1 -1
  32. package/esm/src/schemas/exchange/requests.js +150 -155
  33. package/esm/src/schemas/exchange/requests.js.map +1 -1
  34. package/esm/src/schemas/exchange/responses.d.ts +4 -4
  35. package/esm/src/schemas/explorer/requests.d.ts +2 -2
  36. package/esm/src/schemas/explorer/requests.js +2 -2
  37. package/esm/src/schemas/explorer/requests.js.map +1 -1
  38. package/esm/src/schemas/info/accounts.d.ts +941 -195
  39. package/esm/src/schemas/info/accounts.d.ts.map +1 -1
  40. package/esm/src/schemas/info/accounts.js +44 -0
  41. package/esm/src/schemas/info/accounts.js.map +1 -1
  42. package/esm/src/schemas/info/assets.d.ts +64 -64
  43. package/esm/src/schemas/info/markets.d.ts +16 -16
  44. package/esm/src/schemas/info/orders.d.ts +137 -137
  45. package/esm/src/schemas/info/requests.d.ts +47 -32
  46. package/esm/src/schemas/info/requests.d.ts.map +1 -1
  47. package/esm/src/schemas/info/requests.js +28 -17
  48. package/esm/src/schemas/info/requests.js.map +1 -1
  49. package/esm/src/schemas/info/validators.d.ts +19 -19
  50. package/esm/src/schemas/info/validators.d.ts.map +1 -1
  51. package/esm/src/schemas/info/validators.js +2 -2
  52. package/esm/src/schemas/info/validators.js.map +1 -1
  53. package/esm/src/schemas/info/vaults.d.ts +35 -35
  54. package/esm/src/schemas/mod.d.ts +3 -3
  55. package/esm/src/schemas/mod.d.ts.map +1 -1
  56. package/esm/src/schemas/mod.js +3 -3
  57. package/esm/src/schemas/mod.js.map +1 -1
  58. package/esm/src/schemas/subscriptions/requests.d.ts +2 -2
  59. package/esm/src/schemas/subscriptions/requests.d.ts.map +1 -1
  60. package/esm/src/schemas/subscriptions/requests.js +3 -3
  61. package/esm/src/schemas/subscriptions/requests.js.map +1 -1
  62. package/esm/src/schemas/subscriptions/responses.d.ts +488 -488
  63. package/esm/src/signing/mod.d.ts +1 -1
  64. package/esm/src/signing/mod.d.ts.map +1 -1
  65. package/esm/src/signing/mod.js +2 -2
  66. package/esm/src/signing/mod.js.map +1 -1
  67. package/esm/src/signing/signTypedData/ethers.d.ts.map +1 -0
  68. package/esm/src/signing/signTypedData/ethers.js.map +1 -0
  69. package/esm/src/signing/signTypedData/mod.d.ts.map +1 -0
  70. package/esm/src/signing/signTypedData/mod.js.map +1 -0
  71. package/esm/src/signing/signTypedData/private_key.d.ts.map +1 -0
  72. package/esm/src/signing/{_signTypedData → signTypedData}/private_key.js +9 -8
  73. package/esm/src/signing/signTypedData/private_key.js.map +1 -0
  74. package/esm/src/signing/signTypedData/viem.d.ts.map +1 -0
  75. package/esm/src/signing/signTypedData/viem.js.map +1 -0
  76. package/esm/src/transports/base.d.ts +2 -2
  77. package/esm/src/transports/base.d.ts.map +1 -1
  78. package/esm/src/transports/base.js +2 -2
  79. package/esm/src/transports/base.js.map +1 -1
  80. package/package.json +15 -7
  81. package/script/bin/cli.d.ts +3 -0
  82. package/script/bin/cli.d.ts.map +1 -0
  83. package/script/bin/cli.js +490 -0
  84. package/script/bin/cli.js.map +1 -0
  85. package/script/src/{errors.d.ts → _errors.d.ts} +1 -1
  86. package/script/src/_errors.d.ts.map +1 -0
  87. package/script/src/{errors.js → _errors.js} +1 -1
  88. package/script/src/_errors.js.map +1 -0
  89. package/script/src/clients/exchange.d.ts +4 -4
  90. package/script/src/clients/exchange.d.ts.map +1 -1
  91. package/script/src/clients/exchange.js +5 -5
  92. package/script/src/clients/exchange.js.map +1 -1
  93. package/script/src/clients/info.d.ts +23 -1
  94. package/script/src/clients/info.d.ts.map +1 -1
  95. package/script/src/clients/info.js +26 -0
  96. package/script/src/clients/info.js.map +1 -1
  97. package/script/src/clients/multiSign.d.ts +1 -1
  98. package/script/src/clients/multiSign.d.ts.map +1 -1
  99. package/script/src/clients/multiSign.js +1 -1
  100. package/script/src/clients/multiSign.js.map +1 -1
  101. package/script/src/mod.d.ts +21 -0
  102. package/script/src/mod.d.ts.map +1 -0
  103. package/script/{mod.js → src/mod.js} +12 -8
  104. package/script/src/mod.js.map +1 -0
  105. package/script/src/schemas/_base.d.ts +8 -4
  106. package/script/src/schemas/_base.d.ts.map +1 -1
  107. package/script/src/schemas/_base.js +28 -3
  108. package/script/src/schemas/_base.js.map +1 -1
  109. package/script/src/schemas/exchange/requests.d.ts +1598 -1598
  110. package/script/src/schemas/exchange/requests.d.ts.map +1 -1
  111. package/script/src/schemas/exchange/requests.js +149 -154
  112. package/script/src/schemas/exchange/requests.js.map +1 -1
  113. package/script/src/schemas/exchange/responses.d.ts +4 -4
  114. package/script/src/schemas/explorer/requests.d.ts +2 -2
  115. package/script/src/schemas/explorer/requests.js +1 -1
  116. package/script/src/schemas/explorer/requests.js.map +1 -1
  117. package/script/src/schemas/info/accounts.d.ts +941 -195
  118. package/script/src/schemas/info/accounts.d.ts.map +1 -1
  119. package/script/src/schemas/info/accounts.js +45 -1
  120. package/script/src/schemas/info/accounts.js.map +1 -1
  121. package/script/src/schemas/info/assets.d.ts +64 -64
  122. package/script/src/schemas/info/markets.d.ts +16 -16
  123. package/script/src/schemas/info/orders.d.ts +137 -137
  124. package/script/src/schemas/info/requests.d.ts +47 -32
  125. package/script/src/schemas/info/requests.d.ts.map +1 -1
  126. package/script/src/schemas/info/requests.js +28 -17
  127. package/script/src/schemas/info/requests.js.map +1 -1
  128. package/script/src/schemas/info/validators.d.ts +19 -19
  129. package/script/src/schemas/info/validators.d.ts.map +1 -1
  130. package/script/src/schemas/info/validators.js +2 -2
  131. package/script/src/schemas/info/validators.js.map +1 -1
  132. package/script/src/schemas/info/vaults.d.ts +35 -35
  133. package/script/src/schemas/mod.d.ts +3 -3
  134. package/script/src/schemas/mod.d.ts.map +1 -1
  135. package/script/src/schemas/mod.js +4 -4
  136. package/script/src/schemas/mod.js.map +1 -1
  137. package/script/src/schemas/subscriptions/requests.d.ts +2 -2
  138. package/script/src/schemas/subscriptions/requests.d.ts.map +1 -1
  139. package/script/src/schemas/subscriptions/requests.js +2 -2
  140. package/script/src/schemas/subscriptions/requests.js.map +1 -1
  141. package/script/src/schemas/subscriptions/responses.d.ts +488 -488
  142. package/script/src/signing/mod.d.ts +1 -1
  143. package/script/src/signing/mod.d.ts.map +1 -1
  144. package/script/src/signing/mod.js +3 -3
  145. package/script/src/signing/mod.js.map +1 -1
  146. package/script/src/signing/signTypedData/ethers.d.ts.map +1 -0
  147. package/script/src/signing/signTypedData/ethers.js.map +1 -0
  148. package/script/src/signing/signTypedData/mod.d.ts.map +1 -0
  149. package/script/src/signing/signTypedData/mod.js.map +1 -0
  150. package/script/src/signing/signTypedData/private_key.d.ts.map +1 -0
  151. package/script/src/signing/{_signTypedData → signTypedData}/private_key.js +16 -15
  152. package/script/src/signing/signTypedData/private_key.js.map +1 -0
  153. package/script/src/signing/signTypedData/viem.d.ts.map +1 -0
  154. package/script/src/signing/signTypedData/viem.js.map +1 -0
  155. package/script/src/transports/base.d.ts +2 -2
  156. package/script/src/transports/base.d.ts.map +1 -1
  157. package/script/src/transports/base.js +3 -3
  158. package/script/src/transports/base.js.map +1 -1
  159. package/src/bin/cli.ts +481 -0
  160. package/src/src/clients/exchange.ts +7 -7
  161. package/src/src/clients/info.ts +34 -0
  162. package/src/src/clients/multiSign.ts +2 -2
  163. package/src/src/mod.ts +29 -0
  164. package/src/src/schemas/_base.ts +45 -6
  165. package/src/src/schemas/exchange/requests.ts +150 -155
  166. package/src/src/schemas/explorer/requests.ts +2 -2
  167. package/src/src/schemas/info/accounts.ts +108 -0
  168. package/src/src/schemas/info/requests.ts +49 -17
  169. package/src/src/schemas/info/validators.ts +17 -19
  170. package/src/src/schemas/mod.ts +3 -3
  171. package/src/src/schemas/subscriptions/requests.ts +13 -3
  172. package/src/src/signing/mod.ts +2 -2
  173. package/src/src/signing/{_signTypedData → signTypedData}/private_key.ts +13 -8
  174. package/src/src/transports/base.ts +2 -2
  175. package/esm/mod.d.ts +0 -20
  176. package/esm/mod.d.ts.map +0 -1
  177. package/esm/mod.js +0 -12
  178. package/esm/mod.js.map +0 -1
  179. package/esm/src/errors.d.ts.map +0 -1
  180. package/esm/src/errors.js.map +0 -1
  181. package/esm/src/signing/_signTypedData/ethers.d.ts.map +0 -1
  182. package/esm/src/signing/_signTypedData/ethers.js.map +0 -1
  183. package/esm/src/signing/_signTypedData/mod.d.ts.map +0 -1
  184. package/esm/src/signing/_signTypedData/mod.js.map +0 -1
  185. package/esm/src/signing/_signTypedData/private_key.d.ts.map +0 -1
  186. package/esm/src/signing/_signTypedData/private_key.js.map +0 -1
  187. package/esm/src/signing/_signTypedData/viem.d.ts.map +0 -1
  188. package/esm/src/signing/_signTypedData/viem.js.map +0 -1
  189. package/script/mod.d.ts +0 -20
  190. package/script/mod.d.ts.map +0 -1
  191. package/script/mod.js.map +0 -1
  192. package/script/src/errors.d.ts.map +0 -1
  193. package/script/src/errors.js.map +0 -1
  194. package/script/src/signing/_signTypedData/ethers.d.ts.map +0 -1
  195. package/script/src/signing/_signTypedData/ethers.js.map +0 -1
  196. package/script/src/signing/_signTypedData/mod.d.ts.map +0 -1
  197. package/script/src/signing/_signTypedData/mod.js.map +0 -1
  198. package/script/src/signing/_signTypedData/private_key.d.ts.map +0 -1
  199. package/script/src/signing/_signTypedData/private_key.js.map +0 -1
  200. package/script/src/signing/_signTypedData/viem.d.ts.map +0 -1
  201. package/script/src/signing/_signTypedData/viem.js.map +0 -1
  202. package/src/mod.ts +0 -28
  203. /package/esm/src/signing/{_signTypedData → signTypedData}/ethers.d.ts +0 -0
  204. /package/esm/src/signing/{_signTypedData → signTypedData}/ethers.js +0 -0
  205. /package/esm/src/signing/{_signTypedData → signTypedData}/mod.d.ts +0 -0
  206. /package/esm/src/signing/{_signTypedData → signTypedData}/mod.js +0 -0
  207. /package/esm/src/signing/{_signTypedData → signTypedData}/private_key.d.ts +0 -0
  208. /package/esm/src/signing/{_signTypedData → signTypedData}/viem.d.ts +0 -0
  209. /package/esm/src/signing/{_signTypedData → signTypedData}/viem.js +0 -0
  210. /package/script/src/signing/{_signTypedData → signTypedData}/ethers.d.ts +0 -0
  211. /package/script/src/signing/{_signTypedData → signTypedData}/ethers.js +0 -0
  212. /package/script/src/signing/{_signTypedData → signTypedData}/mod.d.ts +0 -0
  213. /package/script/src/signing/{_signTypedData → signTypedData}/mod.js +0 -0
  214. /package/script/src/signing/{_signTypedData → signTypedData}/private_key.d.ts +0 -0
  215. /package/script/src/signing/{_signTypedData → signTypedData}/viem.d.ts +0 -0
  216. /package/script/src/signing/{_signTypedData → signTypedData}/viem.js +0 -0
  217. /package/src/src/{errors.ts → _errors.ts} +0 -0
  218. /package/src/src/signing/{_signTypedData → signTypedData}/ethers.ts +0 -0
  219. /package/src/src/signing/{_signTypedData → signTypedData}/mod.ts +0 -0
  220. /package/src/src/signing/{_signTypedData → signTypedData}/viem.ts +0 -0
package/src/bin/cli.ts ADDED
@@ -0,0 +1,481 @@
1
+ #!/usr/bin/env node
2
+ import * as hl from "../src/mod.js";
3
+ import { Hex } from "../src/schemas/mod.js";
4
+ import * as v from "valibot";
5
+ import parseArgs from "minimist";
6
+ import process from "node:process";
7
+
8
+ type MethodNames<T> = {
9
+ // deno-lint-ignore no-explicit-any
10
+ [K in Extract<keyof T, string>]: T[K] extends (...args: any[]) => any ? K : never;
11
+ }[Extract<keyof T, string>];
12
+ // deno-lint-ignore no-explicit-any
13
+ function getClassMethods<T>(classConstructor: new (...args: any[]) => T): MethodNames<T>[] {
14
+ return Object.getOwnPropertyNames(classConstructor.prototype)
15
+ .filter((name): name is string => {
16
+ if (name === "constructor") return false;
17
+ const descriptor = Object.getOwnPropertyDescriptor(classConstructor.prototype, name);
18
+ return descriptor?.value && typeof descriptor.value === "function";
19
+ }) as MethodNames<T>[];
20
+ }
21
+ // deno-lint-ignore no-explicit-any
22
+ function isClassMethod<T>(classConstructor: new (...args: any[]) => T, method: string): method is MethodNames<T> {
23
+ const classMethods = getClassMethods(classConstructor);
24
+ // deno-lint-ignore no-explicit-any
25
+ return classMethods.includes(method as any);
26
+ }
27
+
28
+ function transformParams(method: string, params: Record<string, unknown>): Record<string, unknown> {
29
+ switch (method) {
30
+ case "modify": {
31
+ v.assert(v.string(), params?.order);
32
+ return {
33
+ ...params,
34
+ order: JSON.parse(params.order),
35
+ };
36
+ }
37
+ case "convertToMultiSigUser": {
38
+ v.assert(v.string(), params?.authorizedUsers);
39
+ return {
40
+ ...params,
41
+ authorizedUsers: JSON.parse(params.authorizedUsers),
42
+ };
43
+ }
44
+ case "cSignerAction": {
45
+ return {
46
+ ...params,
47
+ jailSelf: "jailSelf" in params ? null : undefined,
48
+ unjailSelf: "unjailSelf" in params ? null : undefined,
49
+ };
50
+ }
51
+ case "order": {
52
+ v.assert(v.string(), params?.orders);
53
+ return {
54
+ ...params,
55
+ orders: JSON.parse(params.orders),
56
+ grouping: params.grouping ?? "na",
57
+ };
58
+ }
59
+ case "approveAgent": {
60
+ return {
61
+ ...params,
62
+ agentName: params.agentName ?? null,
63
+ };
64
+ }
65
+ case "sendAsset": {
66
+ return {
67
+ ...params,
68
+ fromSubAccount: params.fromSubAccount ?? "",
69
+ };
70
+ }
71
+ case "vaultModify": {
72
+ return {
73
+ ...params,
74
+ allowDeposits: params.allowDeposits ?? null,
75
+ alwaysCloseOnWithdraw: params.alwaysCloseOnWithdraw ?? null,
76
+ };
77
+ }
78
+ case "setDisplayName": {
79
+ return {
80
+ ...params,
81
+ displayName: params.displayName ?? "",
82
+ };
83
+ }
84
+ case "batchModify": {
85
+ v.assert(v.string(), params?.modifies);
86
+ return {
87
+ ...params,
88
+ modifies: JSON.parse(params.modifies),
89
+ };
90
+ }
91
+ case "cancel": {
92
+ v.assert(v.string(), params?.cancels);
93
+ return {
94
+ ...params,
95
+ cancels: JSON.parse(params.cancels),
96
+ };
97
+ }
98
+ case "cancelByCloid": {
99
+ v.assert(v.string(), params?.cancels);
100
+ return {
101
+ ...params,
102
+ cancels: JSON.parse(params.cancels),
103
+ };
104
+ }
105
+ case "createVault": {
106
+ return {
107
+ ...params,
108
+ nonce: Date.now(),
109
+ };
110
+ }
111
+ case "spotUser": {
112
+ return {
113
+ toggleSpotDusting: {
114
+ ...params,
115
+ },
116
+ };
117
+ }
118
+ case "twapOrder": {
119
+ return {
120
+ twap: {
121
+ ...params,
122
+ },
123
+ };
124
+ }
125
+ default: {
126
+ return {
127
+ ...params,
128
+ };
129
+ }
130
+ }
131
+ }
132
+
133
+ class EchoTransport implements hl.IRequestTransport {
134
+ constructor(public isTestnet: boolean) {}
135
+ request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown): Promise<T> {
136
+ if (endpoint === "explorer") {
137
+ if (typeof payload === "object" && payload !== null && "type" in payload) {
138
+ if (payload.type === "blockDetails") {
139
+ return new Promise((resolve) => resolve({ blockDetails: payload } as T));
140
+ } else if (payload.type === "txDetails") {
141
+ return new Promise((resolve) => resolve({ tx: payload } as T));
142
+ } else if (payload.type === "userDetails") {
143
+ return new Promise((resolve) => resolve({ txs: payload } as T));
144
+ }
145
+ }
146
+ }
147
+ return new Promise((resolve) => resolve(payload as T));
148
+ }
149
+ }
150
+ class ExchangeClientWithoutValidation extends hl.ExchangeClient {
151
+ override _validateResponse = () => true;
152
+ }
153
+
154
+ async function executeEndpointMethod(
155
+ endpoint: string,
156
+ method: string,
157
+ cliArgs: Record<string, unknown>,
158
+ ): Promise<unknown> {
159
+ const isTestnet = Boolean(cliArgs?.testnet);
160
+ const timeout = Number(cliArgs.timeout) || undefined;
161
+ const isOffline = Boolean(cliArgs?.offline);
162
+
163
+ const transport = isOffline ? new EchoTransport(isTestnet) : new hl.HttpTransport({ isTestnet, timeout });
164
+ let client: hl.InfoClient | hl.ExchangeClient;
165
+
166
+ if (endpoint === "info") {
167
+ if (!isClassMethod(hl.InfoClient, method)) {
168
+ throw new Error(`CLI does not support the "${method}" method in the "info" endpoint`);
169
+ }
170
+
171
+ client = new hl.InfoClient({ transport });
172
+ } else if (endpoint === "exchange") {
173
+ if (!isClassMethod(hl.ExchangeClient, method)) {
174
+ throw new Error(`CLI does not support the "${method}" method in the "exchange" endpoint`);
175
+ }
176
+
177
+ const privateKey = v.parse(
178
+ v.pipe(Hex, v.minLength(66)),
179
+ cliArgs["private-key"],
180
+ { message: 'Invalid format "private-key": Expected 32-byte hexadecimal string' },
181
+ );
182
+ delete cliArgs["private-key"]; // just in case
183
+ const vaultAddress = v.parse(
184
+ v.optional(v.pipe(Hex, v.minLength(42))),
185
+ cliArgs.vault,
186
+ { message: 'Invalid format "vault": Expected 20-byte hexadecimal string OR nothing' },
187
+ );
188
+
189
+ client = isOffline
190
+ ? new ExchangeClientWithoutValidation({
191
+ transport,
192
+ wallet: privateKey,
193
+ defaultVaultAddress: vaultAddress,
194
+ })
195
+ : new hl.ExchangeClient({
196
+ transport,
197
+ wallet: privateKey,
198
+ defaultVaultAddress: vaultAddress,
199
+ });
200
+ } else {
201
+ throw new Error(`Invalid endpoint "${endpoint}". Use "info" or "exchange"`);
202
+ }
203
+
204
+ // @ts-ignore - dynamic method access
205
+ return await client[method](transformParams(method, cliArgs));
206
+ }
207
+
208
+ // ──────────────────── Main ────────────────────
209
+
210
+ function printHelp() {
211
+ console.log(`Hyperliquid CLI
212
+
213
+ Usage:
214
+ npx @nktkas/hyperliquid <endpoint> <method> [options]
215
+
216
+ Endpoints:
217
+ info - Query blockchain and market information
218
+ exchange - Execute trading operations (requires --private-key)
219
+
220
+ Common Options:
221
+ --testnet Use testnet instead of mainnet
222
+ --timeout <number> Request timeout in milliseconds (default: 10000)
223
+ --help, -h Show this help message
224
+ --offline Generate transactions offline without broadcasting
225
+
226
+ Exchange Options:
227
+ --private-key <key> Private key for exchange operations (required)
228
+ --vault <address> Vault address for operations
229
+
230
+ =============================================================================
231
+ INFO ENDPOINT METHODS
232
+ =============================================================================
233
+
234
+ Market Data:
235
+ allMids [--dex <string>]
236
+ l2Book --coin <string> [--nSigFigs <2|3|4|5>] [--mantissa <2|5>]
237
+ candleSnapshot --coin <string> --interval <1m|3m|5m|15m|30m|1h|2h|4h|8h|12h|1d|3d|1w|1M>
238
+ --startTime <number> [--endTime <number>]
239
+ fundingHistory --coin <string> --startTime <number> [--endTime <number>]
240
+ predictedFundings (no params)
241
+ recentTrades --coin <string>
242
+
243
+ Exchange Information:
244
+ meta [--dex <string>]
245
+ metaAndAssetCtxs [--dex <string>]
246
+ spotMeta (no params)
247
+ spotMetaAndAssetCtxs (no params)
248
+ exchangeStatus (no params)
249
+ perpDexs (no params)
250
+ perpDexLimits --dex <string>
251
+ spotPairDeployAuctionStatus (no params)
252
+ perpDeployAuctionStatus (no params)
253
+ perpsAtOpenInterestCap [--dex <string>]
254
+ maxMarketOrderNtls (no params)
255
+ liquidatable (no params)
256
+ marginTable --id <number>
257
+
258
+ User Account Data:
259
+ clearinghouseState --user <address> [--dex <string>]
260
+ spotClearinghouseState --user <address> [--dex <string>]
261
+ portfolio --user <address>
262
+ openOrders --user <address> [--dex <string>]
263
+ frontendOpenOrders --user <address> [--dex <string>]
264
+ historicalOrders --user <address>
265
+ orderStatus --user <address> --oid <number|hex>
266
+ userDetails --user <address>
267
+ userFees --user <address>
268
+ userRateLimit --user <address>
269
+ userRole --user <address>
270
+ activeAssetData --user <address> --coin <string>
271
+ isVip --user <address>
272
+ legalCheck --user <address>
273
+ referral --user <address>
274
+ spotDeployState --user <address>
275
+ preTransferCheck --user <address> --source <address>
276
+ maxBuilderFee --user <address> --builder <address>
277
+ webData2 --user <address>
278
+
279
+ User Trading History:
280
+ userFills --user <address> [--aggregateByTime <bool>]
281
+ userFillsByTime --user <address> --startTime <number> [--endTime <number>] [--aggregateByTime <bool>]
282
+ userFunding --user <address> --startTime <number> [--endTime <number>]
283
+ userNonFundingLedgerUpdates --user <address> --startTime <number> [--endTime <number>]
284
+ twapHistory --user <address>
285
+ userTwapSliceFills --user <address>
286
+ userTwapSliceFillsByTime --user <address> --startTime <number> [--endTime <number>] [--aggregateByTime <bool>]
287
+
288
+ Sub-Account & Multi-Sig:
289
+ subAccounts --user <address>
290
+ extraAgents --user <address>
291
+ userToMultiSigSigners --user <address>
292
+
293
+ Vault Information:
294
+ vaultSummaries (no params)
295
+ vaultDetails --vaultAddress <address> [--user <address>]
296
+ leadingVaults --user <address>
297
+ userVaultEquities --user <address>
298
+
299
+ Delegation & Validators:
300
+ delegations --user <address>
301
+ delegatorHistory --user <address>
302
+ delegatorRewards --user <address>
303
+ delegatorSummary --user <address>
304
+ validatorL1Votes (no params)
305
+ validatorSummaries (no params)
306
+ gossipRootIps (no params)
307
+
308
+ Transaction & Block Details:
309
+ txDetails --hash <hex>
310
+ blockDetails --height <number>
311
+ tokenDetails --tokenId <hex>
312
+
313
+ =============================================================================
314
+ EXCHANGE ENDPOINT METHODS
315
+ =============================================================================
316
+
317
+ Trading Operations:
318
+ order --orders <json> [--grouping <na|normalTpsl|positionTpsl>]
319
+ [--builder <json>]
320
+ modify --oid <number|hex> --order <json>
321
+ batchModify --modifies <json>
322
+ cancel --cancels <json>
323
+ cancelByCloid --cancels <json>
324
+ scheduleCancel [--time <number>]
325
+
326
+ TWAP Operations:
327
+ twapOrder --a <number> --b <bool> --s <string> --r <bool> --m <number> --t <bool>
328
+ twapCancel --a <number> --t <number>
329
+
330
+ Position Management:
331
+ updateLeverage --asset <number> --isCross <bool> --leverage <number>
332
+ updateIsolatedMargin --asset <number> --isBuy <bool> --ntli <number>
333
+
334
+ Fund Transfers:
335
+ withdraw3 --destination <address> --amount <string>
336
+ usdSend --destination <address> --amount <string>
337
+ spotSend --destination <address> --token <name:address> --amount <string>
338
+ sendAsset --destination <address> --token <name:address> --amount <string>
339
+ --sourceDex <string> --destinationDex <string> [--fromSubAccount <address>]
340
+ usdClassTransfer --amount <string> --toPerp <bool>
341
+
342
+ Sub-Account Management:
343
+ createSubAccount --name <string>
344
+ subAccountModify --subAccountUser <address> --name <string>
345
+ subAccountTransfer --subAccountUser <address> --isDeposit <bool> --usd <number>
346
+ subAccountSpotTransfer --subAccountUser <address> --isDeposit <bool>
347
+ --token <name:address> --amount <string>
348
+
349
+ Vault Operations:
350
+ createVault --name <string> --description <string> --initialUsd <number>
351
+ vaultModify --vaultAddress <address> [--allowDeposits <bool>]
352
+ [--alwaysCloseOnWithdraw <bool>]
353
+ vaultTransfer --vaultAddress <address> --isDeposit <bool> --usd <number>
354
+ vaultDistribute --vaultAddress <address> --usd <number>
355
+
356
+ Agent & Referrer:
357
+ approveAgent --agentAddress <address> [--agentName <string>]
358
+ approveBuilderFee --maxFeeRate <number> --builder <address>
359
+ registerReferrer --code <string>
360
+ setReferrer --code <string>
361
+ setDisplayName [--displayName <string>]
362
+
363
+ Staking & Delegation:
364
+ tokenDelegate --validator <address> --wei <number> --isUndelegate <bool>
365
+ cDeposit --wei <number>
366
+ cWithdraw --wei <number>
367
+ claimRewards (no params)
368
+
369
+ Spot & EVM Operations:
370
+ spotUser --optOut <bool>
371
+ evmUserModify --usingBigBlocks <bool>
372
+ reserveRequestWeight --weight <number>
373
+
374
+ Multi-Sig & Advanced:
375
+ convertToMultiSigUser --authorizedUsers <json> --threshold <number>
376
+ cSignerAction --jailSelf | --unjailSelf
377
+ noop (no params)
378
+
379
+ =============================================================================
380
+
381
+ Examples:
382
+ # Get all mid prices
383
+ npx @nktkas/hyperliquid info allMids
384
+
385
+ # Get ETH order book with 3 significant figures
386
+ npx @nktkas/hyperliquid info l2Book --coin ETH --nSigFigs 3
387
+
388
+ # Get user's portfolio
389
+ npx @nktkas/hyperliquid info portfolio --user 0x...
390
+
391
+ # Get candle data for BTC
392
+ npx @nktkas/hyperliquid info candleSnapshot --coin BTC --interval 1h --startTime 1700000000000
393
+
394
+ # Place a limit order
395
+ npx @nktkas/hyperliquid exchange order --private-key 0x... --orders '[{\\"a\\":0,\\"b\\":true,\\"p\\":\\"30000\\",\\"s\\":\\"0.1\\",\\"r\\":false,\\"t\\":{\\"limit\\":{\\"tif\\":\\"Gtc\\"}}}]'
396
+
397
+ # Modify an existing order
398
+ npx @nktkas/hyperliquid exchange modify --private-key 0x... --oid 12345 --order '{\\"a\\":0,\\"b\\":true,\\"p\\":\\"31000\\",\\"s\\":\\"0.1\\",\\"r\\":false,\\"t\\":{\\"limit\\":{\\"tif\\":\\"Gtc\\"}}}'
399
+
400
+ # Cancel orders
401
+ npx @nktkas/hyperliquid exchange cancel --private-key 0x... --cancels '[{\\"a\\":0,\\"o\\":12345}]'
402
+
403
+ # Update leverage
404
+ npx @nktkas/hyperliquid exchange updateLeverage --private-key 0x... --asset 0 --isCross true --leverage 5
405
+
406
+ # Withdraw funds
407
+ npx @nktkas/hyperliquid exchange withdraw3 --private-key 0x... --destination 0x... --amount "100.5"
408
+
409
+ # Send USD to another user
410
+ npx @nktkas/hyperliquid exchange usdSend --private-key 0x... --destination 0x... --amount "50.0"
411
+
412
+ # Create a vault
413
+ npx @nktkas/hyperliquid exchange createVault --private-key 0x... --name "My Vault" --description "Test vault" --initialUsd 1000`);
414
+ }
415
+
416
+ type FindInArgvTypes = "hex" | "bool" | "number" | "empty";
417
+ function findInArgv(types: FindInArgvTypes | FindInArgvTypes[]): string[] {
418
+ // Convert to array if one type is passed in
419
+ const typeArray = Array.isArray(types) ? types : [types];
420
+
421
+ // Validation functions for each type
422
+ const validators = {
423
+ // to avoid converting them to numbers
424
+ hex: (value: string) => /^0[xX][0-9a-fA-F]+$/.test(value),
425
+ // to avoid converting them to strings
426
+ bool: (value: string) => /^(true|false)$/i.test(value),
427
+ // to avoid losing precision in fractional numbers
428
+ number: (value: string) => /^-?\d+(\.\d+)?([eE][+-]?\d+)?$/.test(value),
429
+ // to avoid converting them to booleans
430
+ empty: (value: string) => value === "",
431
+ };
432
+
433
+ const foundKeys = [];
434
+
435
+ for (let i = 0; i < process.argv.length; i++) {
436
+ const arg = process.argv[i];
437
+
438
+ // Processing format --key=value
439
+ if (arg.startsWith("--") && arg.includes("=")) {
440
+ const eqIndex = arg.indexOf("=");
441
+ const key = arg.slice(2, eqIndex);
442
+ const value = arg.slice(eqIndex + 1);
443
+
444
+ // Check value for all requested types
445
+ for (const type of typeArray) {
446
+ if (validators[type] && validators[type](value)) {
447
+ foundKeys.push(key);
448
+ break; // Don't add duplicates
449
+ }
450
+ }
451
+ } // Processing format --key value
452
+ else if (arg.startsWith("--") && i + 1 < process.argv.length) {
453
+ const nextArg = process.argv[i + 1];
454
+ const key = arg.slice(2);
455
+
456
+ // Check value for all requested types
457
+ for (const type of typeArray) {
458
+ if (validators[type] && validators[type](nextArg)) {
459
+ foundKeys.push(key);
460
+ break; // Don't add duplicates
461
+ }
462
+ }
463
+ }
464
+ }
465
+
466
+ return foundKeys;
467
+ }
468
+
469
+ const cliArgs = parseArgs(process.argv.slice(2), {
470
+ boolean: ["testnet", "offline", ...findInArgv("bool")],
471
+ string: ["_", ...findInArgv(["hex", "number", "empty"])],
472
+ });
473
+ const [endpoint, method] = cliArgs._ as string[];
474
+
475
+ if (cliArgs.help || cliArgs.h || !endpoint || !method) {
476
+ printHelp();
477
+ } else {
478
+ executeEndpointMethod(endpoint, method, cliArgs)
479
+ .then((result) => console.log(JSON.stringify(result)))
480
+ .catch((error) => console.error("Error:", error instanceof Error ? error.message : String(error)));
481
+ }
@@ -1,4 +1,4 @@
1
- import { HyperliquidError } from "../errors.js";
1
+ import { HyperliquidError } from "../_errors.js";
2
2
  import type { IRequestTransport } from "../transports/base.js";
3
3
  import {
4
4
  ApproveAgentRequest,
@@ -2060,7 +2060,7 @@ export class ExchangeClient<
2060
2060
  request: {
2061
2061
  action: Record<string, unknown>;
2062
2062
  vaultAddress?: `0x${string}`;
2063
- expiresAfter: number | undefined;
2063
+ expiresAfter: number | string | undefined;
2064
2064
  },
2065
2065
  signal?: AbortSignal,
2066
2066
  ): Promise<T> {
@@ -2074,7 +2074,7 @@ export class ExchangeClient<
2074
2074
  nonce,
2075
2075
  isTestnet: this.transport.isTestnet,
2076
2076
  vaultAddress,
2077
- expiresAfter,
2077
+ expiresAfter: typeof expiresAfter === "string" ? Number(expiresAfter) : expiresAfter,
2078
2078
  });
2079
2079
 
2080
2080
  // Send a request
@@ -2157,9 +2157,9 @@ export class ExchangeClient<
2157
2157
  signatureChainId: `0x${string}`;
2158
2158
  [key: string]: unknown;
2159
2159
  };
2160
- nonce: number;
2160
+ nonce: number | string;
2161
2161
  vaultAddress?: `0x${string}`;
2162
- expiresAfter?: number;
2162
+ expiresAfter?: number | string;
2163
2163
  },
2164
2164
  signal?: AbortSignal,
2165
2165
  ): Promise<T> {
@@ -2169,10 +2169,10 @@ export class ExchangeClient<
2169
2169
  const signature = await signMultiSigAction({
2170
2170
  wallet: this.wallet,
2171
2171
  action,
2172
- nonce,
2172
+ nonce: typeof nonce === "string" ? Number(nonce) : nonce,
2173
2173
  isTestnet: this.transport.isTestnet,
2174
2174
  vaultAddress,
2175
- expiresAfter,
2175
+ expiresAfter: typeof expiresAfter === "string" ? Number(expiresAfter) : expiresAfter,
2176
2176
  });
2177
2177
 
2178
2178
  // Send a request
@@ -117,6 +117,8 @@ import {
117
117
  type VaultLeading,
118
118
  VaultSummariesRequest,
119
119
  type VaultSummary,
120
+ type WebData2,
121
+ WebData2Request,
120
122
  } from "../schemas/mod.js";
121
123
 
122
124
  /** @see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-2191862501 */
@@ -226,6 +228,8 @@ export type UserTwapSliceFillsByTimeParameters = Omit<UserTwapSliceFillsByTimeRe
226
228
  export type UserVaultEquitiesParameters = Omit<UserVaultEquitiesRequest, "type">;
227
229
  /** Request parameters for the {@linkcode InfoClient.vaultDetails} method. */
228
230
  export type VaultDetailsParameters = Omit<VaultDetailsRequest, "type">;
231
+ /** Request parameters for the {@linkcode InfoClient.webData2} method. */
232
+ export type WebData2Parameters = Omit<WebData2Request, "type">;
229
233
 
230
234
  /**
231
235
  * Info client for interacting with the Hyperliquid API.
@@ -2070,6 +2074,36 @@ export class InfoClient<
2070
2074
  return this.transport.request("info", request, signal);
2071
2075
  }
2072
2076
 
2077
+ /**
2078
+ * Request comprehensive user and market data.
2079
+ * @param params - Request-specific parameters.
2080
+ * @param signal - An {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal}. If this option is set, the request can be canceled by calling {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort | abort()} on the corresponding {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController | AbortController}.
2081
+ * @returns Comprehensive user and market data.
2082
+ *
2083
+ * @throws {TransportError} When the transport layer throws an error.
2084
+ *
2085
+ * @see null
2086
+ * @example
2087
+ * ```ts
2088
+ * import * as hl from "@nktkas/hyperliquid";
2089
+ *
2090
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
2091
+ * const infoClient = new hl.InfoClient({ transport });
2092
+ *
2093
+ * const data = await infoClient.webData2({ user: "0x..." });
2094
+ * ```
2095
+ */
2096
+ webData2(
2097
+ params: DeepImmutable<WebData2Parameters>,
2098
+ signal?: AbortSignal,
2099
+ ): Promise<WebData2> {
2100
+ const request = parser(WebData2Request)({
2101
+ type: "webData2",
2102
+ ...params,
2103
+ });
2104
+ return this.transport.request("info", request, signal);
2105
+ }
2106
+
2073
2107
  async [Symbol.asyncDispose](): Promise<void> {
2074
2108
  await this.transport[Symbol.asyncDispose]?.();
2075
2109
  }
@@ -96,7 +96,7 @@ export class MultiSignClient<
96
96
  { type: keyof typeof userSignedActionEip712Types }
97
97
  >;
98
98
  vaultAddress?: `0x${string}`;
99
- expiresAfter: number | undefined;
99
+ expiresAfter: number | string | undefined;
100
100
  },
101
101
  signal?: AbortSignal,
102
102
  ): Promise<T> {
@@ -112,7 +112,7 @@ export class MultiSignClient<
112
112
  nonce,
113
113
  isTestnet: this.transport.isTestnet,
114
114
  vaultAddress,
115
- expiresAfter,
115
+ expiresAfter: typeof expiresAfter === "string" ? Number(expiresAfter) : expiresAfter,
116
116
  });
117
117
  }));
118
118
 
package/src/src/mod.ts ADDED
@@ -0,0 +1,29 @@
1
+ // Base interfaces
2
+ export * from "./_errors.js";
3
+ export * from "./transports/base.js";
4
+
5
+ // Signing
6
+ export type { AbstractWallet } from "./signing/mod.js";
7
+
8
+ // Clients
9
+ export * from "./clients/exchange.js";
10
+ export * from "./clients/info.js";
11
+ export * from "./clients/multiSign.js";
12
+ export * from "./clients/subscription.js";
13
+
14
+ // Transports
15
+ export * from "./transports/http/http_transport.js";
16
+ export * from "./transports/websocket/websocket_transport.js";
17
+
18
+ // Types
19
+ export { SchemaError } from "./schemas/mod.js";
20
+ export type { OrderParams, Signature } from "./schemas/exchange/requests.js";
21
+ export type * from "./schemas/exchange/responses.js";
22
+ export type * from "./schemas/explorer/responses.js";
23
+ export type * from "./schemas/info/accounts.js";
24
+ export type * from "./schemas/info/assets.js";
25
+ export type * from "./schemas/info/validators.js";
26
+ export type * from "./schemas/info/markets.js";
27
+ export type * from "./schemas/info/orders.js";
28
+ export type * from "./schemas/info/vaults.js";
29
+ export type * from "./schemas/subscriptions/responses.js";