@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,3 +1,4 @@
1
+ import { parser, WsActiveAssetCtxRequest, WsActiveAssetDataRequest, WsAllMidsRequest, WsAssetCtxsRequest, WsBboRequest, WsCandleRequest, WsClearinghouseStateRequest, WsExplorerBlockRequest, WsExplorerTxsRequest, WsL2BookRequest, WsNotificationRequest, WsOpenOrdersRequest, WsOrderUpdatesRequest, WsTradesRequest, WsUserEventsRequest, WsUserFillsRequest, WsUserFundingsRequest, WsUserNonFundingLedgerUpdatesRequest, WsUserTwapHistoryRequest, WsUserTwapSliceFillsRequest, WsWebData2Request, } from "../schemas/mod.js";
1
2
  /**
2
3
  * Subscription client for subscribing to various Hyperliquid events.
3
4
  * @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
@@ -41,10 +42,10 @@ export class SubscriptionClient {
41
42
  * ```
42
43
  */
43
44
  activeAssetCtx(params, listener) {
45
+ const payload = parser(WsActiveAssetCtxRequest)({ type: "activeAssetCtx", ...params });
44
46
  const channel = params.coin.startsWith("@") ? "activeSpotAssetCtx" : "activeAssetCtx";
45
- const payload = { type: "activeAssetCtx", ...params };
46
47
  return this.transport.subscribe(channel, payload, (e) => {
47
- if (e.detail.coin === params.coin) {
48
+ if (e.detail.coin === payload.coin) {
48
49
  listener(e.detail);
49
50
  }
50
51
  });
@@ -71,9 +72,9 @@ export class SubscriptionClient {
71
72
  * ```
72
73
  */
73
74
  activeAssetData(params, listener) {
74
- const payload = { type: "activeAssetData", ...params };
75
+ const payload = parser(WsActiveAssetDataRequest)({ type: "activeAssetData", ...params });
75
76
  return this.transport.subscribe(payload.type, payload, (e) => {
76
- if (e.detail.coin === params.coin && e.detail.user === params.user.toLowerCase()) {
77
+ if (e.detail.coin === payload.coin && e.detail.user === payload.user.toLowerCase()) {
77
78
  listener(e.detail);
78
79
  }
79
80
  });
@@ -81,11 +82,25 @@ export class SubscriptionClient {
81
82
  allMids(params_or_listener, maybeListener) {
82
83
  const params = typeof params_or_listener === "function" ? {} : params_or_listener;
83
84
  const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener;
84
- const payload = { type: "allMids", ...params };
85
+ const payload = parser(WsAllMidsRequest)({ type: "allMids", ...params });
85
86
  return this.transport.subscribe(payload.type, payload, (e) => {
86
87
  listener(e.detail);
87
88
  });
88
89
  }
90
+ assetCtxs(params_or_listener, maybeListener) {
91
+ const params = typeof params_or_listener === "function" ? {} : params_or_listener;
92
+ const listener = typeof params_or_listener === "function" ? params_or_listener : maybeListener;
93
+ const payload = parser(WsAssetCtxsRequest)({
94
+ type: "assetCtxs",
95
+ ...params,
96
+ dex: params.dex ?? "",
97
+ });
98
+ return this.transport.subscribe(payload.type, payload, (e) => {
99
+ if (e.detail.dex === payload.dex) {
100
+ listener(e.detail);
101
+ }
102
+ });
103
+ }
89
104
  /**
90
105
  * Subscribe to best bid and offer updates for a specific asset.
91
106
  * @param params - Subscription-specific parameters.
@@ -108,9 +123,9 @@ export class SubscriptionClient {
108
123
  * ```
109
124
  */
110
125
  bbo(params, listener) {
111
- const payload = { type: "bbo", ...params };
126
+ const payload = parser(WsBboRequest)({ type: "bbo", ...params });
112
127
  return this.transport.subscribe(payload.type, payload, (e) => {
113
- if (e.detail.coin === params.coin) {
128
+ if (e.detail.coin === payload.coin) {
114
129
  listener(e.detail);
115
130
  }
116
131
  });
@@ -137,9 +152,42 @@ export class SubscriptionClient {
137
152
  * ```
138
153
  */
139
154
  candle(params, listener) {
140
- const payload = { type: "candle", ...params };
155
+ const payload = parser(WsCandleRequest)({ type: "candle", ...params });
156
+ return this.transport.subscribe(payload.type, payload, (e) => {
157
+ if (e.detail.s === payload.coin && e.detail.i === payload.interval) {
158
+ listener(e.detail);
159
+ }
160
+ });
161
+ }
162
+ /**
163
+ * Subscribe to clearinghouse state updates for a specific user.
164
+ * @param params - Subscription-specific parameters.
165
+ * @param listener - A callback function to be called when the event is received.
166
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
167
+ *
168
+ * @throws {TransportError} When the transport layer throws an error.
169
+ *
170
+ * @see null
171
+ * @example
172
+ * ```ts
173
+ * import * as hl from "@nktkas/hyperliquid";
174
+ *
175
+ * const transport = new hl.WebSocketTransport();
176
+ * const subsClient = new hl.SubscriptionClient({ transport });
177
+ *
178
+ * const sub = await subsClient.clearinghouseState({ user: "0x..." }, (data) => {
179
+ * console.log(data);
180
+ * });
181
+ * ```
182
+ */
183
+ clearinghouseState(params, listener) {
184
+ const payload = parser(WsClearinghouseStateRequest)({
185
+ type: "clearinghouseState",
186
+ ...params,
187
+ dex: params.dex ?? "",
188
+ });
141
189
  return this.transport.subscribe(payload.type, payload, (e) => {
142
- if (e.detail.s === params.coin && e.detail.i === params.interval) {
190
+ if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
143
191
  listener(e.detail);
144
192
  }
145
193
  });
@@ -166,7 +214,7 @@ export class SubscriptionClient {
166
214
  * ```
167
215
  */
168
216
  explorerBlock(listener) {
169
- const payload = { type: "explorerBlock" };
217
+ const payload = parser(WsExplorerBlockRequest)({ type: "explorerBlock" });
170
218
  return this.transport.subscribe("_explorerBlock", payload, (e) => {
171
219
  listener(e.detail);
172
220
  });
@@ -193,7 +241,7 @@ export class SubscriptionClient {
193
241
  * ```
194
242
  */
195
243
  explorerTxs(listener) {
196
- const payload = { type: "explorerTxs" };
244
+ const payload = parser(WsExplorerTxsRequest)({ type: "explorerTxs" });
197
245
  return this.transport.subscribe("_explorerTxs", payload, (e) => {
198
246
  listener(e.detail);
199
247
  });
@@ -220,14 +268,14 @@ export class SubscriptionClient {
220
268
  * ```
221
269
  */
222
270
  l2Book(params, listener) {
223
- const payload = {
271
+ const payload = parser(WsL2BookRequest)({
224
272
  type: "l2Book",
225
273
  ...params,
226
274
  nSigFigs: params.nSigFigs ?? null,
227
275
  mantissa: params.mantissa ?? null,
228
- };
276
+ });
229
277
  return this.transport.subscribe(payload.type, payload, (e) => {
230
- if (e.detail.coin === params.coin) {
278
+ if (e.detail.coin === payload.coin) {
231
279
  listener(e.detail);
232
280
  }
233
281
  });
@@ -254,11 +302,44 @@ export class SubscriptionClient {
254
302
  * ```
255
303
  */
256
304
  notification(params, listener) {
257
- const payload = { type: "notification", ...params };
305
+ const payload = parser(WsNotificationRequest)({ type: "notification", ...params });
258
306
  return this.transport.subscribe(payload.type, payload, (e) => {
259
307
  listener(e.detail);
260
308
  });
261
309
  }
310
+ /**
311
+ * Subscribe to open orders updates for a specific user.
312
+ * @param params - Subscription-specific parameters.
313
+ * @param listener - A callback function to be called when the event is received.
314
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
315
+ *
316
+ * @throws {TransportError} When the transport layer throws an error.
317
+ *
318
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
319
+ * @example
320
+ * ```ts
321
+ * import * as hl from "@nktkas/hyperliquid";
322
+ *
323
+ * const transport = new hl.WebSocketTransport();
324
+ * const subsClient = new hl.SubscriptionClient({ transport });
325
+ *
326
+ * const sub = await subsClient.openOrders({ user: "0x..." }, (data) => {
327
+ * console.log(data);
328
+ * });
329
+ * ```
330
+ */
331
+ openOrders(params, listener) {
332
+ const payload = parser(WsOpenOrdersRequest)({
333
+ type: "openOrders",
334
+ ...params,
335
+ dex: params.dex ?? "",
336
+ });
337
+ return this.transport.subscribe(payload.type, payload, (e) => {
338
+ if (e.detail.user === payload.user.toLowerCase() && e.detail.dex === payload.dex) {
339
+ listener(e.detail);
340
+ }
341
+ });
342
+ }
262
343
  /**
263
344
  * Subscribe to order status updates for a specific user.
264
345
  * @param params - Subscription-specific parameters.
@@ -281,7 +362,7 @@ export class SubscriptionClient {
281
362
  * ```
282
363
  */
283
364
  orderUpdates(params, listener) {
284
- const payload = { type: "orderUpdates", ...params };
365
+ const payload = parser(WsOrderUpdatesRequest)({ type: "orderUpdates", ...params });
285
366
  return this.transport.subscribe(payload.type, payload, (e) => {
286
367
  listener(e.detail);
287
368
  });
@@ -308,9 +389,9 @@ export class SubscriptionClient {
308
389
  * ```
309
390
  */
310
391
  trades(params, listener) {
311
- const payload = { type: "trades", ...params };
392
+ const payload = parser(WsTradesRequest)({ type: "trades", ...params });
312
393
  return this.transport.subscribe(payload.type, payload, (e) => {
313
- if (e.detail[0]?.coin === params.coin) {
394
+ if (e.detail[0]?.coin === payload.coin) {
314
395
  listener(e.detail);
315
396
  }
316
397
  });
@@ -338,7 +419,7 @@ export class SubscriptionClient {
338
419
  * ```
339
420
  */
340
421
  userEvents(params, listener) {
341
- const payload = { type: "userEvents", ...params };
422
+ const payload = parser(WsUserEventsRequest)({ type: "userEvents", ...params });
342
423
  return this.transport.subscribe("user", payload, (e) => {
343
424
  listener(e.detail);
344
425
  });
@@ -365,13 +446,13 @@ export class SubscriptionClient {
365
446
  * ```
366
447
  */
367
448
  userFills(params, listener) {
368
- const payload = {
449
+ const payload = parser(WsUserFillsRequest)({
369
450
  type: "userFills",
370
451
  ...params,
371
452
  aggregateByTime: params.aggregateByTime ?? false,
372
- };
453
+ });
373
454
  return this.transport.subscribe(payload.type, payload, (e) => {
374
- if (e.detail.user === params.user.toLowerCase()) {
455
+ if (e.detail.user === payload.user.toLowerCase()) {
375
456
  listener(e.detail);
376
457
  }
377
458
  });
@@ -398,9 +479,9 @@ export class SubscriptionClient {
398
479
  * ```
399
480
  */
400
481
  userFundings(params, listener) {
401
- const payload = { type: "userFundings", ...params };
482
+ const payload = parser(WsUserFundingsRequest)({ type: "userFundings", ...params });
402
483
  return this.transport.subscribe(payload.type, payload, (e) => {
403
- if (e.detail.user === params.user.toLowerCase()) {
484
+ if (e.detail.user === payload.user.toLowerCase()) {
404
485
  listener(e.detail);
405
486
  }
406
487
  });
@@ -427,12 +508,12 @@ export class SubscriptionClient {
427
508
  * ```
428
509
  */
429
510
  userNonFundingLedgerUpdates(params, listener) {
430
- const payload = {
511
+ const payload = parser(WsUserNonFundingLedgerUpdatesRequest)({
431
512
  type: "userNonFundingLedgerUpdates",
432
513
  ...params,
433
- };
514
+ });
434
515
  return this.transport.subscribe(payload.type, payload, (e) => {
435
- if (e.detail.user === params.user.toLowerCase()) {
516
+ if (e.detail.user === payload.user.toLowerCase()) {
436
517
  listener(e.detail);
437
518
  }
438
519
  });
@@ -459,9 +540,9 @@ export class SubscriptionClient {
459
540
  * ```
460
541
  */
461
542
  userTwapHistory(params, listener) {
462
- const payload = { type: "userTwapHistory", ...params };
543
+ const payload = parser(WsUserTwapHistoryRequest)({ type: "userTwapHistory", ...params });
463
544
  return this.transport.subscribe(payload.type, payload, (e) => {
464
- if (e.detail.user === params.user.toLowerCase()) {
545
+ if (e.detail.user === payload.user.toLowerCase()) {
465
546
  listener(e.detail);
466
547
  }
467
548
  });
@@ -488,9 +569,9 @@ export class SubscriptionClient {
488
569
  * ```
489
570
  */
490
571
  userTwapSliceFills(params, listener) {
491
- const payload = { type: "userTwapSliceFills", ...params };
572
+ const payload = parser(WsUserTwapSliceFillsRequest)({ type: "userTwapSliceFills", ...params });
492
573
  return this.transport.subscribe(payload.type, payload, (e) => {
493
- if (e.detail.user === params.user.toLowerCase()) {
574
+ if (e.detail.user === payload.user.toLowerCase()) {
494
575
  listener(e.detail);
495
576
  }
496
577
  });
@@ -517,9 +598,9 @@ export class SubscriptionClient {
517
598
  * ```
518
599
  */
519
600
  webData2(params, listener) {
520
- const payload = { type: "webData2", ...params };
601
+ const payload = parser(WsWebData2Request)({ type: "webData2", ...params });
521
602
  return this.transport.subscribe(payload.type, payload, (e) => {
522
- if (e.detail.user === params.user.toLowerCase()) {
603
+ if (e.detail.user === payload.user.toLowerCase()) {
523
604
  listener(e.detail);
524
605
  }
525
606
  });
@@ -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,12 @@
1
+ import * as v from "valibot";
2
+ export const UnsignedDecimal = v.pipe(v.string(), v.regex(/^[0-9]+(\.[0-9]+)?$/), v.transform((value) => formatDecimal(value)));
3
+ export const SignedDecimal = v.pipe(v.string(), v.regex(/^-?[0-9]+(\.[0-9]+)?$/), v.transform((value) => formatDecimal(value)));
4
+ export const Hex = v.pipe(v.string(), v.regex(/^0[xX][0-9a-fA-F]+$/), v.transform((value) => value.toLowerCase()));
5
+ export const TokenId = v.pipe(v.string(), v.regex(/^[^:]+:0x[0-9a-fA-F]+$/), v.transform((value) => value));
6
+ /** Removes leading/trailing zeros from decimal string without precision loss. */
7
+ function formatDecimal(numStr) {
8
+ return numStr
9
+ .replace(/^(-?)0+(?=\d)/, "$1") // Remove leading zeros, keep sign
10
+ .replace(/(\.\d*?)0+$/, "$1") // Remove trailing zeros after decimal
11
+ .replace(/\.$/, ""); // Remove lone decimal point
12
+ }