@nktkas/hyperliquid 0.24.2 → 0.25.0-beta.1

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 (242) hide show
  1. package/README.md +197 -117
  2. package/esm/mod.d.ts +11 -11
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/mod.js +1 -1
  5. package/esm/src/clients/exchange.d.ts +29 -18
  6. package/esm/src/clients/exchange.d.ts.map +1 -1
  7. package/esm/src/clients/exchange.js +50 -48
  8. package/esm/src/clients/info.d.ts +79 -75
  9. package/esm/src/clients/info.d.ts.map +1 -1
  10. package/esm/src/clients/info.js +294 -163
  11. package/esm/src/clients/multiSign.d.ts +11 -7
  12. package/esm/src/clients/multiSign.d.ts.map +1 -1
  13. package/esm/src/clients/subscription.d.ts +105 -32
  14. package/esm/src/clients/subscription.d.ts.map +1 -1
  15. package/esm/src/clients/subscription.js +114 -33
  16. package/esm/src/{base.d.ts → errors.d.ts} +1 -1
  17. package/esm/src/errors.d.ts.map +1 -0
  18. package/esm/src/schemas/_base.d.ts +10 -0
  19. package/esm/src/schemas/_base.d.ts.map +1 -0
  20. package/esm/src/schemas/_base.js +12 -0
  21. package/esm/src/schemas/exchange/requests.d.ts +8953 -0
  22. package/esm/src/schemas/exchange/requests.d.ts.map +1 -0
  23. package/esm/src/schemas/exchange/requests.js +1413 -0
  24. package/esm/src/schemas/exchange/responses.d.ts +567 -0
  25. package/esm/src/schemas/exchange/responses.d.ts.map +1 -0
  26. package/esm/src/schemas/exchange/responses.js +243 -0
  27. package/esm/src/schemas/explorer/requests.d.ts +44 -0
  28. package/esm/src/schemas/explorer/requests.d.ts.map +1 -0
  29. package/esm/src/schemas/explorer/requests.js +32 -0
  30. package/esm/src/schemas/explorer/responses.d.ts +360 -0
  31. package/esm/src/schemas/explorer/responses.d.ts.map +1 -0
  32. package/esm/src/schemas/explorer/responses.js +56 -0
  33. package/esm/src/schemas/info/accounts.d.ts +2159 -0
  34. package/esm/src/schemas/info/accounts.d.ts.map +1 -0
  35. package/esm/src/schemas/info/accounts.js +622 -0
  36. package/esm/src/schemas/info/assets.d.ts +945 -0
  37. package/esm/src/schemas/info/assets.d.ts.map +1 -0
  38. package/esm/src/schemas/info/assets.js +265 -0
  39. package/esm/src/schemas/info/markets.d.ts +138 -0
  40. package/esm/src/schemas/info/markets.d.ts.map +1 -0
  41. package/esm/src/schemas/info/markets.js +58 -0
  42. package/esm/src/schemas/info/orders.d.ts +957 -0
  43. package/esm/src/schemas/info/orders.d.ts.map +1 -0
  44. package/esm/src/schemas/info/orders.js +297 -0
  45. package/esm/src/schemas/info/requests.d.ts +882 -0
  46. package/esm/src/schemas/info/requests.d.ts.map +1 -0
  47. package/esm/src/schemas/info/requests.js +655 -0
  48. package/esm/src/schemas/info/validators.d.ts +305 -0
  49. package/esm/src/schemas/info/validators.d.ts.map +1 -0
  50. package/esm/src/schemas/info/validators.js +112 -0
  51. package/esm/src/schemas/info/vaults.d.ts +447 -0
  52. package/esm/src/schemas/info/vaults.d.ts.map +1 -0
  53. package/esm/src/schemas/info/vaults.js +110 -0
  54. package/esm/src/schemas/mod.d.ts +100 -0
  55. package/esm/src/schemas/mod.d.ts.map +1 -0
  56. package/esm/src/schemas/mod.js +113 -0
  57. package/esm/src/schemas/subscriptions/requests.d.ts +332 -0
  58. package/esm/src/schemas/subscriptions/requests.d.ts.map +1 -0
  59. package/esm/src/schemas/subscriptions/requests.js +258 -0
  60. package/esm/src/schemas/subscriptions/responses.d.ts +3643 -0
  61. package/esm/src/schemas/subscriptions/responses.d.ts.map +1 -0
  62. package/esm/src/schemas/subscriptions/responses.js +233 -0
  63. package/esm/src/signing/mod.d.ts +109 -29
  64. package/esm/src/signing/mod.d.ts.map +1 -1
  65. package/esm/src/signing/mod.js +135 -29
  66. package/esm/src/transports/base.d.ts +2 -2
  67. package/esm/src/transports/base.d.ts.map +1 -1
  68. package/esm/src/transports/base.js +2 -2
  69. package/esm/src/transports/http/http_transport.d.ts +2 -1
  70. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  71. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  72. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  73. package/esm/src/transports/websocket/websocket_transport.d.ts +2 -1
  74. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  75. package/package.json +6 -5
  76. package/script/mod.d.ts +11 -11
  77. package/script/mod.d.ts.map +1 -1
  78. package/script/mod.js +1 -1
  79. package/script/src/clients/exchange.d.ts +29 -18
  80. package/script/src/clients/exchange.d.ts.map +1 -1
  81. package/script/src/clients/exchange.js +56 -54
  82. package/script/src/clients/info.d.ts +79 -75
  83. package/script/src/clients/info.d.ts.map +1 -1
  84. package/script/src/clients/info.js +294 -163
  85. package/script/src/clients/multiSign.d.ts +11 -7
  86. package/script/src/clients/multiSign.d.ts.map +1 -1
  87. package/script/src/clients/subscription.d.ts +105 -32
  88. package/script/src/clients/subscription.d.ts.map +1 -1
  89. package/script/src/clients/subscription.js +114 -33
  90. package/script/src/{base.d.ts → errors.d.ts} +1 -1
  91. package/script/src/errors.d.ts.map +1 -0
  92. package/script/src/schemas/_base.d.ts +10 -0
  93. package/script/src/schemas/_base.d.ts.map +1 -0
  94. package/script/src/schemas/_base.js +48 -0
  95. package/script/src/schemas/exchange/requests.d.ts +8953 -0
  96. package/script/src/schemas/exchange/requests.d.ts.map +1 -0
  97. package/script/src/schemas/exchange/requests.js +1449 -0
  98. package/script/src/schemas/exchange/responses.d.ts +567 -0
  99. package/script/src/schemas/exchange/responses.d.ts.map +1 -0
  100. package/script/src/schemas/exchange/responses.js +279 -0
  101. package/script/src/schemas/explorer/requests.d.ts +44 -0
  102. package/script/src/schemas/explorer/requests.d.ts.map +1 -0
  103. package/script/src/schemas/explorer/requests.js +68 -0
  104. package/script/src/schemas/explorer/responses.d.ts +360 -0
  105. package/script/src/schemas/explorer/responses.d.ts.map +1 -0
  106. package/script/src/schemas/explorer/responses.js +92 -0
  107. package/script/src/schemas/info/accounts.d.ts +2159 -0
  108. package/script/src/schemas/info/accounts.d.ts.map +1 -0
  109. package/script/src/schemas/info/accounts.js +658 -0
  110. package/script/src/schemas/info/assets.d.ts +945 -0
  111. package/script/src/schemas/info/assets.d.ts.map +1 -0
  112. package/script/src/schemas/info/assets.js +301 -0
  113. package/script/src/schemas/info/markets.d.ts +138 -0
  114. package/script/src/schemas/info/markets.d.ts.map +1 -0
  115. package/script/src/schemas/info/markets.js +94 -0
  116. package/script/src/schemas/info/orders.d.ts +957 -0
  117. package/script/src/schemas/info/orders.d.ts.map +1 -0
  118. package/script/src/schemas/info/orders.js +333 -0
  119. package/script/src/schemas/info/requests.d.ts +882 -0
  120. package/script/src/schemas/info/requests.d.ts.map +1 -0
  121. package/script/src/schemas/info/requests.js +692 -0
  122. package/script/src/schemas/info/validators.d.ts +305 -0
  123. package/script/src/schemas/info/validators.d.ts.map +1 -0
  124. package/script/src/schemas/info/validators.js +148 -0
  125. package/script/src/schemas/info/vaults.d.ts +447 -0
  126. package/script/src/schemas/info/vaults.d.ts.map +1 -0
  127. package/script/src/schemas/info/vaults.js +146 -0
  128. package/script/src/schemas/mod.d.ts +100 -0
  129. package/script/src/schemas/mod.d.ts.map +1 -0
  130. package/script/src/schemas/mod.js +154 -0
  131. package/script/src/schemas/subscriptions/requests.d.ts +332 -0
  132. package/script/src/schemas/subscriptions/requests.d.ts.map +1 -0
  133. package/script/src/schemas/subscriptions/requests.js +294 -0
  134. package/script/src/schemas/subscriptions/responses.d.ts +3643 -0
  135. package/script/src/schemas/subscriptions/responses.d.ts.map +1 -0
  136. package/script/src/schemas/subscriptions/responses.js +269 -0
  137. package/script/src/signing/mod.d.ts +109 -29
  138. package/script/src/signing/mod.d.ts.map +1 -1
  139. package/script/src/signing/mod.js +137 -33
  140. package/script/src/transports/base.d.ts +2 -2
  141. package/script/src/transports/base.d.ts.map +1 -1
  142. package/script/src/transports/base.js +3 -3
  143. package/script/src/transports/http/http_transport.d.ts +2 -1
  144. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  145. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  146. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  147. package/script/src/transports/websocket/websocket_transport.d.ts +2 -1
  148. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  149. package/esm/src/base.d.ts.map +0 -1
  150. package/esm/src/signing/_sorter.d.ts +0 -127
  151. package/esm/src/signing/_sorter.d.ts.map +0 -1
  152. package/esm/src/signing/_sorter.js +0 -693
  153. package/esm/src/types/exchange/requests.d.ts +0 -1345
  154. package/esm/src/types/exchange/requests.d.ts.map +0 -1
  155. package/esm/src/types/exchange/requests.js +0 -1
  156. package/esm/src/types/exchange/responses.d.ts +0 -233
  157. package/esm/src/types/exchange/responses.d.ts.map +0 -1
  158. package/esm/src/types/exchange/responses.js +0 -1
  159. package/esm/src/types/explorer/requests.d.ts +0 -32
  160. package/esm/src/types/explorer/requests.d.ts.map +0 -1
  161. package/esm/src/types/explorer/requests.js +0 -1
  162. package/esm/src/types/explorer/responses.d.ts +0 -58
  163. package/esm/src/types/explorer/responses.d.ts.map +0 -1
  164. package/esm/src/types/explorer/responses.js +0 -1
  165. package/esm/src/types/info/accounts.d.ts +0 -864
  166. package/esm/src/types/info/accounts.d.ts.map +0 -1
  167. package/esm/src/types/info/accounts.js +0 -1
  168. package/esm/src/types/info/assets.d.ts +0 -354
  169. package/esm/src/types/info/assets.d.ts.map +0 -1
  170. package/esm/src/types/info/assets.js +0 -1
  171. package/esm/src/types/info/markets.d.ts +0 -79
  172. package/esm/src/types/info/markets.d.ts.map +0 -1
  173. package/esm/src/types/info/markets.js +0 -1
  174. package/esm/src/types/info/orders.d.ts +0 -266
  175. package/esm/src/types/info/orders.d.ts.map +0 -1
  176. package/esm/src/types/info/orders.js +0 -1
  177. package/esm/src/types/info/requests.d.ts +0 -634
  178. package/esm/src/types/info/requests.d.ts.map +0 -1
  179. package/esm/src/types/info/requests.js +0 -1
  180. package/esm/src/types/info/validators.d.ts +0 -147
  181. package/esm/src/types/info/validators.d.ts.map +0 -1
  182. package/esm/src/types/info/validators.js +0 -1
  183. package/esm/src/types/info/vaults.d.ts +0 -119
  184. package/esm/src/types/info/vaults.d.ts.map +0 -1
  185. package/esm/src/types/info/vaults.js +0 -1
  186. package/esm/src/types/mod.d.ts +0 -38
  187. package/esm/src/types/mod.d.ts.map +0 -1
  188. package/esm/src/types/mod.js +0 -24
  189. package/esm/src/types/subscriptions/requests.d.ts +0 -143
  190. package/esm/src/types/subscriptions/requests.d.ts.map +0 -1
  191. package/esm/src/types/subscriptions/requests.js +0 -1
  192. package/esm/src/types/subscriptions/responses.d.ts +0 -213
  193. package/esm/src/types/subscriptions/responses.d.ts.map +0 -1
  194. package/esm/src/types/subscriptions/responses.js +0 -1
  195. package/script/src/base.d.ts.map +0 -1
  196. package/script/src/signing/_sorter.d.ts +0 -127
  197. package/script/src/signing/_sorter.d.ts.map +0 -1
  198. package/script/src/signing/_sorter.js +0 -696
  199. package/script/src/types/exchange/requests.d.ts +0 -1345
  200. package/script/src/types/exchange/requests.d.ts.map +0 -1
  201. package/script/src/types/exchange/requests.js +0 -2
  202. package/script/src/types/exchange/responses.d.ts +0 -233
  203. package/script/src/types/exchange/responses.d.ts.map +0 -1
  204. package/script/src/types/exchange/responses.js +0 -2
  205. package/script/src/types/explorer/requests.d.ts +0 -32
  206. package/script/src/types/explorer/requests.d.ts.map +0 -1
  207. package/script/src/types/explorer/requests.js +0 -2
  208. package/script/src/types/explorer/responses.d.ts +0 -58
  209. package/script/src/types/explorer/responses.d.ts.map +0 -1
  210. package/script/src/types/explorer/responses.js +0 -2
  211. package/script/src/types/info/accounts.d.ts +0 -864
  212. package/script/src/types/info/accounts.d.ts.map +0 -1
  213. package/script/src/types/info/accounts.js +0 -2
  214. package/script/src/types/info/assets.d.ts +0 -354
  215. package/script/src/types/info/assets.d.ts.map +0 -1
  216. package/script/src/types/info/assets.js +0 -2
  217. package/script/src/types/info/markets.d.ts +0 -79
  218. package/script/src/types/info/markets.d.ts.map +0 -1
  219. package/script/src/types/info/markets.js +0 -2
  220. package/script/src/types/info/orders.d.ts +0 -266
  221. package/script/src/types/info/orders.d.ts.map +0 -1
  222. package/script/src/types/info/orders.js +0 -2
  223. package/script/src/types/info/requests.d.ts +0 -634
  224. package/script/src/types/info/requests.d.ts.map +0 -1
  225. package/script/src/types/info/requests.js +0 -2
  226. package/script/src/types/info/validators.d.ts +0 -147
  227. package/script/src/types/info/validators.d.ts.map +0 -1
  228. package/script/src/types/info/validators.js +0 -2
  229. package/script/src/types/info/vaults.d.ts +0 -119
  230. package/script/src/types/info/vaults.d.ts.map +0 -1
  231. package/script/src/types/info/vaults.js +0 -2
  232. package/script/src/types/mod.d.ts +0 -38
  233. package/script/src/types/mod.d.ts.map +0 -1
  234. package/script/src/types/mod.js +0 -25
  235. package/script/src/types/subscriptions/requests.d.ts +0 -143
  236. package/script/src/types/subscriptions/requests.d.ts.map +0 -1
  237. package/script/src/types/subscriptions/requests.js +0 -2
  238. package/script/src/types/subscriptions/responses.d.ts +0 -213
  239. package/script/src/types/subscriptions/responses.d.ts.map +0 -1
  240. package/script/src/types/subscriptions/responses.js +0 -2
  241. /package/esm/src/{base.js → errors.js} +0 -0
  242. /package/script/src/{base.js → errors.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubscriptionClient = void 0;
4
+ const mod_js_1 = require("../schemas/mod.js");
4
5
  /**
5
6
  * Subscription client for subscribing to various Hyperliquid events.
6
7
  * @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
@@ -44,10 +45,10 @@ class SubscriptionClient {
44
45
  * ```
45
46
  */
46
47
  activeAssetCtx(params, listener) {
48
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsActiveAssetCtxRequest)({ type: "activeAssetCtx", ...params });
47
49
  const channel = params.coin.startsWith("@") ? "activeSpotAssetCtx" : "activeAssetCtx";
48
- const payload = { type: "activeAssetCtx", ...params };
49
50
  return this.transport.subscribe(channel, payload, (e) => {
50
- if (e.detail.coin === params.coin) {
51
+ if (e.detail.coin === payload.coin) {
51
52
  listener(e.detail);
52
53
  }
53
54
  });
@@ -74,9 +75,9 @@ class SubscriptionClient {
74
75
  * ```
75
76
  */
76
77
  activeAssetData(params, listener) {
77
- const payload = { type: "activeAssetData", ...params };
78
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsActiveAssetDataRequest)({ type: "activeAssetData", ...params });
78
79
  return this.transport.subscribe(payload.type, payload, (e) => {
79
- if (e.detail.coin === params.coin && e.detail.user === params.user.toLowerCase()) {
80
+ if (e.detail.coin === payload.coin && e.detail.user === payload.user.toLowerCase()) {
80
81
  listener(e.detail);
81
82
  }
82
83
  });
@@ -84,11 +85,25 @@ class SubscriptionClient {
84
85
  allMids(params_or_listener, maybeListener) {
85
86
  const params = typeof params_or_listener === "function" ? {} : params_or_listener;
86
87
  const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener;
87
- const payload = { type: "allMids", ...params };
88
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsAllMidsRequest)({ type: "allMids", ...params });
88
89
  return this.transport.subscribe(payload.type, payload, (e) => {
89
90
  listener(e.detail);
90
91
  });
91
92
  }
93
+ assetCtxs(params_or_listener, maybeListener) {
94
+ const params = typeof params_or_listener === "function" ? {} : params_or_listener;
95
+ const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener;
96
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsAssetCtxsRequest)({
97
+ type: "assetCtxs",
98
+ ...params,
99
+ dex: params.dex ?? "",
100
+ });
101
+ return this.transport.subscribe(payload.type, payload, (e) => {
102
+ if (e.detail.dex === payload.dex) {
103
+ listener(e.detail);
104
+ }
105
+ });
106
+ }
92
107
  /**
93
108
  * Subscribe to best bid and offer updates for a specific asset.
94
109
  * @param params - Subscription-specific parameters.
@@ -111,9 +126,9 @@ class SubscriptionClient {
111
126
  * ```
112
127
  */
113
128
  bbo(params, listener) {
114
- const payload = { type: "bbo", ...params };
129
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsBboRequest)({ type: "bbo", ...params });
115
130
  return this.transport.subscribe(payload.type, payload, (e) => {
116
- if (e.detail.coin === params.coin) {
131
+ if (e.detail.coin === payload.coin) {
117
132
  listener(e.detail);
118
133
  }
119
134
  });
@@ -140,9 +155,42 @@ class SubscriptionClient {
140
155
  * ```
141
156
  */
142
157
  candle(params, listener) {
143
- const payload = { type: "candle", ...params };
158
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsCandleRequest)({ type: "candle", ...params });
159
+ return this.transport.subscribe(payload.type, payload, (e) => {
160
+ if (e.detail.s === payload.coin && e.detail.i === payload.interval) {
161
+ listener(e.detail);
162
+ }
163
+ });
164
+ }
165
+ /**
166
+ * Subscribe to clearinghouse state updates for a specific user.
167
+ * @param params - Subscription-specific parameters.
168
+ * @param listener - A callback function to be called when the event is received.
169
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
170
+ *
171
+ * @throws {TransportError} When the transport layer throws an error.
172
+ *
173
+ * @see null
174
+ * @example
175
+ * ```ts
176
+ * import * as hl from "@nktkas/hyperliquid";
177
+ *
178
+ * const transport = new hl.WebSocketTransport();
179
+ * const subsClient = new hl.SubscriptionClient({ transport });
180
+ *
181
+ * const sub = await subsClient.clearinghouseState({ user: "0x..." }, (data) => {
182
+ * console.log(data);
183
+ * });
184
+ * ```
185
+ */
186
+ clearinghouseState(params, listener) {
187
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsClearinghouseStateRequest)({
188
+ type: "clearinghouseState",
189
+ ...params,
190
+ dex: params.dex ?? "",
191
+ });
144
192
  return this.transport.subscribe(payload.type, payload, (e) => {
145
- if (e.detail.s === params.coin && e.detail.i === params.interval) {
193
+ if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
146
194
  listener(e.detail);
147
195
  }
148
196
  });
@@ -169,7 +217,7 @@ class SubscriptionClient {
169
217
  * ```
170
218
  */
171
219
  explorerBlock(listener) {
172
- const payload = { type: "explorerBlock" };
220
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsExplorerBlockRequest)({ type: "explorerBlock" });
173
221
  return this.transport.subscribe("_explorerBlock", payload, (e) => {
174
222
  listener(e.detail);
175
223
  });
@@ -196,7 +244,7 @@ class SubscriptionClient {
196
244
  * ```
197
245
  */
198
246
  explorerTxs(listener) {
199
- const payload = { type: "explorerTxs" };
247
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsExplorerTxsRequest)({ type: "explorerTxs" });
200
248
  return this.transport.subscribe("_explorerTxs", payload, (e) => {
201
249
  listener(e.detail);
202
250
  });
@@ -223,14 +271,14 @@ class SubscriptionClient {
223
271
  * ```
224
272
  */
225
273
  l2Book(params, listener) {
226
- const payload = {
274
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsL2BookRequest)({
227
275
  type: "l2Book",
228
276
  ...params,
229
277
  nSigFigs: params.nSigFigs ?? null,
230
278
  mantissa: params.mantissa ?? null,
231
- };
279
+ });
232
280
  return this.transport.subscribe(payload.type, payload, (e) => {
233
- if (e.detail.coin === params.coin) {
281
+ if (e.detail.coin === payload.coin) {
234
282
  listener(e.detail);
235
283
  }
236
284
  });
@@ -257,11 +305,44 @@ class SubscriptionClient {
257
305
  * ```
258
306
  */
259
307
  notification(params, listener) {
260
- const payload = { type: "notification", ...params };
308
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsNotificationRequest)({ type: "notification", ...params });
261
309
  return this.transport.subscribe(payload.type, payload, (e) => {
262
310
  listener(e.detail);
263
311
  });
264
312
  }
313
+ /**
314
+ * Subscribe to open orders updates for a specific user.
315
+ * @param params - Subscription-specific parameters.
316
+ * @param listener - A callback function to be called when the event is received.
317
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
318
+ *
319
+ * @throws {TransportError} When the transport layer throws an error.
320
+ *
321
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
322
+ * @example
323
+ * ```ts
324
+ * import * as hl from "@nktkas/hyperliquid";
325
+ *
326
+ * const transport = new hl.WebSocketTransport();
327
+ * const subsClient = new hl.SubscriptionClient({ transport });
328
+ *
329
+ * const sub = await subsClient.openOrders({ user: "0x..." }, (data) => {
330
+ * console.log(data);
331
+ * });
332
+ * ```
333
+ */
334
+ openOrders(params, listener) {
335
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsOpenOrdersRequest)({
336
+ type: "openOrders",
337
+ ...params,
338
+ dex: params.dex ?? "",
339
+ });
340
+ return this.transport.subscribe(payload.type, payload, (e) => {
341
+ if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
342
+ listener(e.detail);
343
+ }
344
+ });
345
+ }
265
346
  /**
266
347
  * Subscribe to order status updates for a specific user.
267
348
  * @param params - Subscription-specific parameters.
@@ -284,7 +365,7 @@ class SubscriptionClient {
284
365
  * ```
285
366
  */
286
367
  orderUpdates(params, listener) {
287
- const payload = { type: "orderUpdates", ...params };
368
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsOrderUpdatesRequest)({ type: "orderUpdates", ...params });
288
369
  return this.transport.subscribe(payload.type, payload, (e) => {
289
370
  listener(e.detail);
290
371
  });
@@ -311,9 +392,9 @@ class SubscriptionClient {
311
392
  * ```
312
393
  */
313
394
  trades(params, listener) {
314
- const payload = { type: "trades", ...params };
395
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsTradesRequest)({ type: "trades", ...params });
315
396
  return this.transport.subscribe(payload.type, payload, (e) => {
316
- if (e.detail[0]?.coin === params.coin) {
397
+ if (e.detail[0]?.coin === payload.coin) {
317
398
  listener(e.detail);
318
399
  }
319
400
  });
@@ -341,7 +422,7 @@ class SubscriptionClient {
341
422
  * ```
342
423
  */
343
424
  userEvents(params, listener) {
344
- const payload = { type: "userEvents", ...params };
425
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserEventsRequest)({ type: "userEvents", ...params });
345
426
  return this.transport.subscribe("user", payload, (e) => {
346
427
  listener(e.detail);
347
428
  });
@@ -368,13 +449,13 @@ class SubscriptionClient {
368
449
  * ```
369
450
  */
370
451
  userFills(params, listener) {
371
- const payload = {
452
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserFillsRequest)({
372
453
  type: "userFills",
373
454
  ...params,
374
455
  aggregateByTime: params.aggregateByTime ?? false,
375
- };
456
+ });
376
457
  return this.transport.subscribe(payload.type, payload, (e) => {
377
- if (e.detail.user === params.user.toLowerCase()) {
458
+ if (e.detail.user === payload.user.toLowerCase()) {
378
459
  listener(e.detail);
379
460
  }
380
461
  });
@@ -401,9 +482,9 @@ class SubscriptionClient {
401
482
  * ```
402
483
  */
403
484
  userFundings(params, listener) {
404
- const payload = { type: "userFundings", ...params };
485
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserFundingsRequest)({ type: "userFundings", ...params });
405
486
  return this.transport.subscribe(payload.type, payload, (e) => {
406
- if (e.detail.user === params.user.toLowerCase()) {
487
+ if (e.detail.user === payload.user.toLowerCase()) {
407
488
  listener(e.detail);
408
489
  }
409
490
  });
@@ -430,12 +511,12 @@ class SubscriptionClient {
430
511
  * ```
431
512
  */
432
513
  userNonFundingLedgerUpdates(params, listener) {
433
- const payload = {
514
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserNonFundingLedgerUpdatesRequest)({
434
515
  type: "userNonFundingLedgerUpdates",
435
516
  ...params,
436
- };
517
+ });
437
518
  return this.transport.subscribe(payload.type, payload, (e) => {
438
- if (e.detail.user === params.user.toLowerCase()) {
519
+ if (e.detail.user === payload.user.toLowerCase()) {
439
520
  listener(e.detail);
440
521
  }
441
522
  });
@@ -462,9 +543,9 @@ class SubscriptionClient {
462
543
  * ```
463
544
  */
464
545
  userTwapHistory(params, listener) {
465
- const payload = { type: "userTwapHistory", ...params };
546
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserTwapHistoryRequest)({ type: "userTwapHistory", ...params });
466
547
  return this.transport.subscribe(payload.type, payload, (e) => {
467
- if (e.detail.user === params.user.toLowerCase()) {
548
+ if (e.detail.user === payload.user.toLowerCase()) {
468
549
  listener(e.detail);
469
550
  }
470
551
  });
@@ -491,9 +572,9 @@ class SubscriptionClient {
491
572
  * ```
492
573
  */
493
574
  userTwapSliceFills(params, listener) {
494
- const payload = { type: "userTwapSliceFills", ...params };
575
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsUserTwapSliceFillsRequest)({ type: "userTwapSliceFills", ...params });
495
576
  return this.transport.subscribe(payload.type, payload, (e) => {
496
- if (e.detail.user === params.user.toLowerCase()) {
577
+ if (e.detail.user === payload.user.toLowerCase()) {
497
578
  listener(e.detail);
498
579
  }
499
580
  });
@@ -520,9 +601,9 @@ class SubscriptionClient {
520
601
  * ```
521
602
  */
522
603
  webData2(params, listener) {
523
- const payload = { type: "webData2", ...params };
604
+ const payload = (0, mod_js_1.parser)(mod_js_1.WsWebData2Request)({ type: "webData2", ...params });
524
605
  return this.transport.subscribe(payload.type, payload, (e) => {
525
- if (e.detail.user === params.user.toLowerCase()) {
606
+ if (e.detail.user === payload.user.toLowerCase()) {
526
607
  listener(e.detail);
527
608
  }
528
609
  });
@@ -2,4 +2,4 @@
2
2
  export declare class HyperliquidError extends Error {
3
3
  constructor(message?: string, options?: ErrorOptions);
4
4
  }
5
- //# sourceMappingURL=base.d.ts.map
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/src/errors.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
@@ -0,0 +1,10 @@
1
+ import * as v from "valibot";
2
+ export declare const UnsignedDecimal: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, string>]>;
3
+ export type UnsignedDecimal = v.InferOutput<typeof UnsignedDecimal>;
4
+ export declare const SignedDecimal: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, string>]>;
5
+ export type SignedDecimal = v.InferOutput<typeof SignedDecimal>;
6
+ export declare const Hex: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `0x${string}`>]>;
7
+ export type Hex = v.InferOutput<typeof Hex>;
8
+ export declare const TokenId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.TransformAction<string, `${string}:0x${string}`>]>;
9
+ export type TokenId = v.InferOutput<typeof TokenId>;
10
+ //# sourceMappingURL=_base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_base.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/_base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,eAAO,MAAM,eAAe,6HAI3B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,eAAe,CAAC,CAAC;AAEpE,eAAO,MAAM,aAAa,6HAIzB,CAAC;AACF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,aAAa,CAAC,CAAC;AAEhE,eAAO,MAAM,GAAG,oIAIf,CAAC;AACF,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC;AAE5C,eAAO,MAAM,OAAO,8IAInB,CAAC;AACF,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,OAAO,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.TokenId = exports.Hex = exports.SignedDecimal = exports.UnsignedDecimal = void 0;
37
+ const v = __importStar(require("valibot"));
38
+ exports.UnsignedDecimal = v.pipe(v.string(), v.regex(/^[0-9]+(\.[0-9]+)?$/), v.transform((value) => formatDecimal(value)));
39
+ exports.SignedDecimal = v.pipe(v.string(), v.regex(/^-?[0-9]+(\.[0-9]+)?$/), v.transform((value) => formatDecimal(value)));
40
+ exports.Hex = v.pipe(v.string(), v.regex(/^0[xX][0-9a-fA-F]+$/), v.transform((value) => value.toLowerCase()));
41
+ exports.TokenId = v.pipe(v.string(), v.regex(/^[^:]+:0x[0-9a-fA-F]+$/), v.transform((value) => value));
42
+ /** Removes leading/trailing zeros from decimal string without precision loss. */
43
+ function formatDecimal(numStr) {
44
+ return numStr
45
+ .replace(/^(-?)0+(?=\d)/, "$1") // Remove leading zeros, keep sign
46
+ .replace(/(\.\d*?)0+$/, "$1") // Remove trailing zeros after decimal
47
+ .replace(/\.$/, ""); // Remove lone decimal point
48
+ }