@nktkas/hyperliquid 0.22.2 → 0.23.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 (256) hide show
  1. package/README.md +79 -67
  2. package/esm/mod.d.ts +1 -1
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/src/base.d.ts +4 -1
  5. package/esm/src/base.d.ts.map +1 -1
  6. package/esm/src/base.js +2 -2
  7. package/esm/src/clients/exchange.d.ts +289 -207
  8. package/esm/src/clients/exchange.d.ts.map +1 -1
  9. package/esm/src/clients/exchange.js +605 -410
  10. package/esm/src/clients/info.d.ts +264 -48
  11. package/esm/src/clients/info.d.ts.map +1 -1
  12. package/esm/src/clients/info.js +273 -31
  13. package/esm/src/clients/multiSign.d.ts +285 -204
  14. package/esm/src/clients/multiSign.d.ts.map +1 -1
  15. package/esm/src/clients/multiSign.js +521 -493
  16. package/esm/src/clients/subscription.d.ts +38 -3
  17. package/esm/src/clients/subscription.d.ts.map +1 -1
  18. package/esm/src/clients/subscription.js +36 -3
  19. package/esm/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
  20. package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  21. package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
  22. package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
  23. package/esm/src/signing/_signTypedData/mod.js +59 -0
  24. package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
  25. package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  26. package/esm/src/signing/_signTypedData/private_key.js +144 -0
  27. package/esm/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
  28. package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
  29. package/{script/src/signing/_window.d.ts → esm/src/signing/_signTypedData/window.d.ts} +18 -12
  30. package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
  31. package/esm/src/signing/{_window.js → _signTypedData/window.js} +3 -2
  32. package/esm/src/signing/_sorter.d.ts +56 -82
  33. package/esm/src/signing/_sorter.d.ts.map +1 -1
  34. package/esm/src/signing/_sorter.js +36 -49
  35. package/esm/src/signing/mod.d.ts +151 -130
  36. package/esm/src/signing/mod.d.ts.map +1 -1
  37. package/esm/src/signing/mod.js +182 -228
  38. package/esm/src/transports/base.d.ts +1 -1
  39. package/esm/src/transports/base.d.ts.map +1 -1
  40. package/esm/src/transports/base.js +2 -2
  41. package/esm/src/transports/http/http_transport.d.ts +9 -15
  42. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  43. package/esm/src/transports/http/http_transport.js +64 -59
  44. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  45. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  46. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
  47. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  48. package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
  49. package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  50. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  51. package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
  52. package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
  53. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  54. package/esm/src/transports/websocket/websocket_transport.js +83 -54
  55. package/esm/src/types/exchange/requests.d.ts +27 -51
  56. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  57. package/esm/src/types/explorer/requests.d.ts +5 -8
  58. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  59. package/esm/src/types/info/accounts.d.ts +5 -5
  60. package/esm/src/types/info/accounts.d.ts.map +1 -1
  61. package/esm/src/types/info/markets.d.ts +6 -0
  62. package/esm/src/types/info/markets.d.ts.map +1 -1
  63. package/esm/src/types/info/orders.d.ts +1 -1
  64. package/esm/src/types/info/orders.d.ts.map +1 -1
  65. package/esm/src/types/info/requests.d.ts +129 -124
  66. package/esm/src/types/info/requests.d.ts.map +1 -1
  67. package/{script/src/types/info/delegations.d.ts → esm/src/types/info/validators.d.ts} +2 -2
  68. package/esm/src/types/info/validators.d.ts.map +1 -0
  69. package/esm/src/types/info/vaults.d.ts +7 -0
  70. package/esm/src/types/info/vaults.d.ts.map +1 -1
  71. package/esm/src/types/mod.d.ts +1 -1
  72. package/esm/src/types/mod.d.ts.map +1 -1
  73. package/esm/src/types/subscriptions/requests.d.ts +72 -18
  74. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  75. package/esm/src/types/subscriptions/responses.d.ts +2 -0
  76. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  77. package/package.json +8 -5
  78. package/script/mod.d.ts +1 -1
  79. package/script/mod.d.ts.map +1 -1
  80. package/script/mod.js +13 -23
  81. package/script/src/base.d.ts +4 -1
  82. package/script/src/base.d.ts.map +1 -1
  83. package/script/src/base.js +10 -20
  84. package/script/src/clients/exchange.d.ts +289 -207
  85. package/script/src/clients/exchange.d.ts.map +1 -1
  86. package/script/src/clients/exchange.js +2000 -1815
  87. package/script/src/clients/info.d.ts +264 -48
  88. package/script/src/clients/info.d.ts.map +1 -1
  89. package/script/src/clients/info.js +1442 -1210
  90. package/script/src/clients/multiSign.d.ts +285 -204
  91. package/script/src/clients/multiSign.d.ts.map +1 -1
  92. package/script/src/clients/multiSign.js +2043 -2025
  93. package/script/src/clients/subscription.d.ts +38 -3
  94. package/script/src/clients/subscription.d.ts.map +1 -1
  95. package/script/src/clients/subscription.js +568 -545
  96. package/script/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
  97. package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  98. package/script/src/signing/_signTypedData/ethers.js +16 -0
  99. package/script/src/signing/_signTypedData/mod.d.ts +35 -0
  100. package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
  101. package/script/src/signing/_signTypedData/mod.js +67 -0
  102. package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
  103. package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  104. package/script/src/signing/_signTypedData/private_key.js +148 -0
  105. package/script/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
  106. package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
  107. package/script/src/signing/_signTypedData/viem.js +9 -0
  108. package/{esm/src/signing/_window.d.ts → script/src/signing/_signTypedData/window.d.ts} +18 -12
  109. package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
  110. package/script/src/signing/_signTypedData/window.js +34 -0
  111. package/script/src/signing/_sorter.d.ts +56 -82
  112. package/script/src/signing/_sorter.d.ts.map +1 -1
  113. package/script/src/signing/_sorter.js +655 -678
  114. package/script/src/signing/mod.d.ts +151 -130
  115. package/script/src/signing/mod.d.ts.map +1 -1
  116. package/script/src/signing/mod.js +286 -342
  117. package/script/src/transports/base.d.ts +1 -1
  118. package/script/src/transports/base.d.ts.map +1 -1
  119. package/script/src/transports/base.js +11 -21
  120. package/script/src/transports/http/http_transport.d.ts +9 -15
  121. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  122. package/script/src/transports/http/http_transport.js +97 -102
  123. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  124. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  125. package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
  126. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  127. package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
  128. package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  129. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  130. package/script/src/transports/websocket/_websocket_async_request.js +157 -174
  131. package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
  132. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  133. package/script/src/transports/websocket/websocket_transport.js +209 -189
  134. package/script/src/types/exchange/requests.d.ts +27 -51
  135. package/script/src/types/exchange/requests.d.ts.map +1 -1
  136. package/script/src/types/exchange/requests.js +2 -12
  137. package/script/src/types/exchange/responses.js +2 -12
  138. package/script/src/types/explorer/requests.d.ts +5 -8
  139. package/script/src/types/explorer/requests.d.ts.map +1 -1
  140. package/script/src/types/explorer/requests.js +2 -12
  141. package/script/src/types/explorer/responses.js +2 -12
  142. package/script/src/types/info/accounts.d.ts +5 -5
  143. package/script/src/types/info/accounts.d.ts.map +1 -1
  144. package/script/src/types/info/accounts.js +2 -12
  145. package/script/src/types/info/assets.js +2 -12
  146. package/script/src/types/info/markets.d.ts +6 -0
  147. package/script/src/types/info/markets.d.ts.map +1 -1
  148. package/script/src/types/info/markets.js +2 -12
  149. package/script/src/types/info/orders.d.ts +1 -1
  150. package/script/src/types/info/orders.d.ts.map +1 -1
  151. package/script/src/types/info/orders.js +2 -12
  152. package/script/src/types/info/requests.d.ts +129 -124
  153. package/script/src/types/info/requests.d.ts.map +1 -1
  154. package/script/src/types/info/requests.js +2 -12
  155. package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +2 -2
  156. package/script/src/types/info/validators.d.ts.map +1 -0
  157. package/script/src/types/info/validators.js +2 -0
  158. package/script/src/types/info/vaults.d.ts +7 -0
  159. package/script/src/types/info/vaults.d.ts.map +1 -1
  160. package/script/src/types/info/vaults.js +2 -12
  161. package/script/src/types/mod.d.ts +1 -1
  162. package/script/src/types/mod.d.ts.map +1 -1
  163. package/script/src/types/mod.js +2 -12
  164. package/script/src/types/subscriptions/requests.d.ts +72 -18
  165. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  166. package/script/src/types/subscriptions/requests.js +2 -12
  167. package/script/src/types/subscriptions/responses.d.ts +2 -0
  168. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  169. package/script/src/types/subscriptions/responses.js +2 -12
  170. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  171. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  172. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
  173. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  174. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  175. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
  176. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  177. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  178. package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
  179. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  180. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  181. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
  182. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  183. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  184. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
  185. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  186. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  187. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  188. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  189. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  190. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  191. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  192. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  193. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  194. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  195. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  196. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  197. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  198. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  199. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
  200. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  201. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  202. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
  203. package/esm/src/signing/_ethers.d.ts.map +0 -1
  204. package/esm/src/signing/_private_key.d.ts +0 -22
  205. package/esm/src/signing/_private_key.d.ts.map +0 -1
  206. package/esm/src/signing/_private_key.js +0 -124
  207. package/esm/src/signing/_viem.d.ts.map +0 -1
  208. package/esm/src/signing/_window.d.ts.map +0 -1
  209. package/esm/src/types/info/delegations.d.ts.map +0 -1
  210. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  211. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  212. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
  213. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  214. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  215. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
  216. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  217. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  218. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
  219. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  220. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  221. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
  222. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  223. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  224. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
  225. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  226. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  227. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
  228. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  229. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  230. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
  231. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  232. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  233. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
  234. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  235. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  236. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
  237. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  238. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  239. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
  240. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  241. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  242. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
  243. package/script/src/signing/_ethers.d.ts.map +0 -1
  244. package/script/src/signing/_ethers.js +0 -26
  245. package/script/src/signing/_private_key.d.ts +0 -22
  246. package/script/src/signing/_private_key.d.ts.map +0 -1
  247. package/script/src/signing/_private_key.js +0 -138
  248. package/script/src/signing/_viem.d.ts.map +0 -1
  249. package/script/src/signing/_viem.js +0 -19
  250. package/script/src/signing/_window.d.ts.map +0 -1
  251. package/script/src/signing/_window.js +0 -43
  252. package/script/src/types/info/delegations.d.ts.map +0 -1
  253. package/script/src/types/info/delegations.js +0 -12
  254. /package/esm/src/signing/{_ethers.js → _signTypedData/ethers.js} +0 -0
  255. /package/esm/src/signing/{_viem.js → _signTypedData/viem.js} +0 -0
  256. /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
@@ -1,556 +1,579 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SubscriptionClient = void 0;
4
+ /**
5
+ * Subscription client for subscribing to various Hyperliquid events.
6
+ * @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
7
+ */
8
+ class SubscriptionClient {
9
+ transport;
10
+ /**
11
+ * Initialises a new instance.
12
+ * @param args - The arguments for initialisation.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import * as hl from "@nktkas/hyperliquid";
17
+ *
18
+ * const transport = new hl.WebSocketTransport();
19
+ * const subsClient = new hl.SubscriptionClient({ transport });
20
+ * ```
21
+ */
22
+ constructor(args) {
23
+ this.transport = args.transport;
5
24
  }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
25
+ /**
26
+ * Subscribe to context updates for a specific perpetual asset.
27
+ * @param args - The parameters for the subscription.
28
+ * @param listener - The callback function to be called when the event is received.
29
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
30
+ *
31
+ * @throws {TransportError} When the transport layer throws an error.
32
+ *
33
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
34
+ * @example
35
+ * ```ts
36
+ * import * as hl from "@nktkas/hyperliquid";
37
+ *
38
+ * const transport = new hl.WebSocketTransport();
39
+ * const subsClient = new hl.SubscriptionClient({ transport });
40
+ *
41
+ * const sub = await subsClient.activeAssetCtx({ coin: "BTC" }, (data) => {
42
+ * console.log(data);
43
+ * });
44
+ * ```
45
+ */
46
+ activeAssetCtx(args, listener) {
47
+ const channel = args.coin.startsWith("@") ? "activeSpotAssetCtx" : "activeAssetCtx";
48
+ const payload = {
49
+ type: "activeAssetCtx",
50
+ coin: args.coin,
51
+ };
52
+ return this.transport.subscribe(channel, payload, (e) => {
53
+ if (e.detail.coin === args.coin) {
54
+ listener(e.detail);
55
+ }
56
+ });
8
57
  }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SubscriptionClient = void 0;
13
58
  /**
14
- * Subscription client for subscribing to various Hyperliquid events.
15
- * @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
59
+ * Subscribe to trading data updates for a specific asset and user.
60
+ * @param args - The parameters for the subscription.
61
+ * @param listener - The callback function to be called when the event is received.
62
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
63
+ *
64
+ * @throws {TransportError} When the transport layer throws an error.
65
+ *
66
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
67
+ * @example
68
+ * ```ts
69
+ * import * as hl from "@nktkas/hyperliquid";
70
+ *
71
+ * const transport = new hl.WebSocketTransport();
72
+ * const subsClient = new hl.SubscriptionClient({ transport });
73
+ *
74
+ * const sub = await subsClient.activeAssetData({ coin: "BTC", user: "0x..." }, (data) => {
75
+ * console.log(data);
76
+ * });
77
+ * ```
16
78
  */
17
- class SubscriptionClient {
18
- transport;
19
- /**
20
- * Initialises a new instance.
21
- * @param args - The arguments for initialisation.
22
- *
23
- * @example
24
- * ```ts
25
- * import * as hl from "@nktkas/hyperliquid";
26
- *
27
- * const transport = new hl.WebSocketTransport();
28
- * const subsClient = new hl.SubscriptionClient({ transport });
29
- * ```
30
- */
31
- constructor(args) {
32
- this.transport = args.transport;
33
- }
34
- /**
35
- * Subscribe to context updates for a specific perpetual asset.
36
- * @param args - The parameters for the subscription.
37
- * @param listener - The callback function to be called when the event is received.
38
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
39
- *
40
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
41
- * @example
42
- * ```ts
43
- * import * as hl from "@nktkas/hyperliquid";
44
- *
45
- * const transport = new hl.WebSocketTransport();
46
- * const subsClient = new hl.SubscriptionClient({ transport });
47
- *
48
- * const sub = await subsClient.activeAssetCtx({ coin: "BTC" }, (data) => {
49
- * console.log(data);
50
- * });
51
- * ```
52
- */
53
- activeAssetCtx(args, listener) {
54
- const channel = args.coin.startsWith("@") ? "activeSpotAssetCtx" : "activeAssetCtx";
55
- const payload = {
56
- type: "activeAssetCtx",
57
- coin: args.coin,
58
- };
59
- return this.transport.subscribe(channel, payload, (e) => {
60
- if (e.detail.coin === args.coin) {
61
- listener(e.detail);
62
- }
63
- });
64
- }
65
- /**
66
- * Subscribe to trading data updates for a specific asset and user.
67
- * @param args - The parameters for the subscription.
68
- * @param listener - The callback function to be called when the event is received.
69
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
70
- *
71
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
72
- * @example
73
- * ```ts
74
- * import * as hl from "@nktkas/hyperliquid";
75
- *
76
- * const transport = new hl.WebSocketTransport();
77
- * const subsClient = new hl.SubscriptionClient({ transport });
78
- *
79
- * const sub = await subsClient.activeAssetData({ coin: "BTC", user: "0x..." }, (data) => {
80
- * console.log(data);
81
- * });
82
- * ```
83
- */
84
- activeAssetData(args, listener) {
85
- const payload = {
86
- type: "activeAssetData",
87
- coin: args.coin,
88
- user: args.user,
89
- };
90
- return this.transport.subscribe(payload.type, payload, (e) => {
91
- if (e.detail.coin === args.coin && e.detail.user === args.user.toLowerCase()) {
92
- listener(e.detail);
93
- }
94
- });
95
- }
96
- allMids(args_or_listener, maybeListener) {
97
- const args = typeof args_or_listener === "function" ? {} : args_or_listener;
98
- const listener = typeof args_or_listener === "function" ? args_or_listener : maybeListener;
99
- const payload = {
100
- type: "allMids",
101
- dex: args.dex,
102
- };
103
- return this.transport.subscribe(payload.type, payload, (e) => {
79
+ activeAssetData(args, listener) {
80
+ const payload = {
81
+ type: "activeAssetData",
82
+ coin: args.coin,
83
+ user: args.user,
84
+ };
85
+ return this.transport.subscribe(payload.type, payload, (e) => {
86
+ if (e.detail.coin === args.coin && e.detail.user === args.user.toLowerCase()) {
104
87
  listener(e.detail);
105
- });
106
- }
107
- /**
108
- * Subscribe to best bid and offer updates for a specific asset.
109
- * @param args - The parameters for the subscription.
110
- * @param listener - The callback function to be called when the event is received.
111
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
112
- *
113
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
114
- * @example
115
- * ```ts
116
- * import * as hl from "@nktkas/hyperliquid";
117
- *
118
- * const transport = new hl.WebSocketTransport();
119
- * const subsClient = new hl.SubscriptionClient({ transport });
120
- *
121
- * const sub = await subsClient.bbo({ coin: "BTC" }, (data) => {
122
- * console.log(data);
123
- * });
124
- * ```
125
- */
126
- bbo(args, listener) {
127
- const payload = {
128
- type: "bbo",
129
- coin: args.coin,
130
- };
131
- return this.transport.subscribe(payload.type, payload, (e) => {
132
- if (e.detail.coin === args.coin) {
133
- listener(e.detail);
134
- }
135
- });
136
- }
137
- /**
138
- * Subscribe to candlestick data updates for a specific asset.
139
- * @param args - The parameters for the subscription.
140
- * @param listener - The callback function to be called when the event is received.
141
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
142
- *
143
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
144
- * @example
145
- * ```ts
146
- * import * as hl from "@nktkas/hyperliquid";
147
- *
148
- * const transport = new hl.WebSocketTransport();
149
- * const subsClient = new hl.SubscriptionClient({ transport });
150
- *
151
- * const sub = await subsClient.candle({ coin: "BTC", interval: "1h" }, (data) => {
152
- * console.log(data);
153
- * });
154
- * ```
155
- */
156
- candle(args, listener) {
157
- const payload = {
158
- type: "candle",
159
- coin: args.coin,
160
- interval: args.interval,
161
- };
162
- return this.transport.subscribe(payload.type, payload, (e) => {
163
- if (e.detail.s === args.coin && e.detail.i === args.interval) {
164
- listener(e.detail);
165
- }
166
- });
167
- }
168
- /**
169
- * Subscribe to explorer block updates.
170
- * @param listener - The callback function to be called when the event is received.
171
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
172
- * @note Make sure the endpoint in the {@link transport} supports this method.
173
- *
174
- * @see null - no documentation
175
- * @example
176
- * ```ts
177
- * import * as hl from "@nktkas/hyperliquid";
178
- *
179
- * const transport = new hl.WebSocketTransport();
180
- * const subsClient = new hl.SubscriptionClient({ transport });
181
- *
182
- * const sub = await subsClient.explorerBlock((data) => {
183
- * console.log(data);
184
- * });
185
- * ```
186
- */
187
- explorerBlock(listener) {
188
- const payload = {
189
- type: "explorerBlock",
190
- };
191
- return this.transport.subscribe("_explorerBlock", payload, (e) => {
88
+ }
89
+ });
90
+ }
91
+ allMids(args_or_listener, maybeListener) {
92
+ const args = typeof args_or_listener === "function" ? {} : args_or_listener;
93
+ const listener = typeof args_or_listener === "function" ? args_or_listener : maybeListener;
94
+ const payload = {
95
+ type: "allMids",
96
+ dex: args.dex,
97
+ };
98
+ return this.transport.subscribe(payload.type, payload, (e) => {
99
+ listener(e.detail);
100
+ });
101
+ }
102
+ /**
103
+ * Subscribe to best bid and offer updates for a specific asset.
104
+ * @param args - The parameters for the subscription.
105
+ * @param listener - The callback function to be called when the event is received.
106
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
107
+ *
108
+ * @throws {TransportError} When the transport layer throws an error.
109
+ *
110
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
111
+ * @example
112
+ * ```ts
113
+ * import * as hl from "@nktkas/hyperliquid";
114
+ *
115
+ * const transport = new hl.WebSocketTransport();
116
+ * const subsClient = new hl.SubscriptionClient({ transport });
117
+ *
118
+ * const sub = await subsClient.bbo({ coin: "BTC" }, (data) => {
119
+ * console.log(data);
120
+ * });
121
+ * ```
122
+ */
123
+ bbo(args, listener) {
124
+ const payload = {
125
+ type: "bbo",
126
+ coin: args.coin,
127
+ };
128
+ return this.transport.subscribe(payload.type, payload, (e) => {
129
+ if (e.detail.coin === args.coin) {
192
130
  listener(e.detail);
193
- });
194
- }
195
- /**
196
- * Subscribe to explorer transaction updates.
197
- * @param listener - The callback function to be called when the event is received.
198
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
199
- * @note Make sure the endpoint in the {@link transport} supports this method.
200
- *
201
- * @see null - no documentation
202
- * @example
203
- * ```ts
204
- * import * as hl from "@nktkas/hyperliquid";
205
- *
206
- * const transport = new hl.WebSocketTransport();
207
- * const subsClient = new hl.SubscriptionClient({ transport });
208
- *
209
- * const sub = await subsClient.explorerTxs((data) => {
210
- * console.log(data);
211
- * });
212
- * ```
213
- */
214
- explorerTxs(listener) {
215
- const payload = {
216
- type: "explorerTxs",
217
- };
218
- return this.transport.subscribe("_explorerTxs", payload, (e) => {
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * Subscribe to candlestick data updates for a specific asset.
136
+ * @param args - The parameters for the subscription.
137
+ * @param listener - The callback function to be called when the event is received.
138
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
139
+ *
140
+ * @throws {TransportError} When the transport layer throws an error.
141
+ *
142
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
143
+ * @example
144
+ * ```ts
145
+ * import * as hl from "@nktkas/hyperliquid";
146
+ *
147
+ * const transport = new hl.WebSocketTransport();
148
+ * const subsClient = new hl.SubscriptionClient({ transport });
149
+ *
150
+ * const sub = await subsClient.candle({ coin: "BTC", interval: "1h" }, (data) => {
151
+ * console.log(data);
152
+ * });
153
+ * ```
154
+ */
155
+ candle(args, listener) {
156
+ const payload = {
157
+ type: "candle",
158
+ coin: args.coin,
159
+ interval: args.interval,
160
+ };
161
+ return this.transport.subscribe(payload.type, payload, (e) => {
162
+ if (e.detail.s === args.coin && e.detail.i === args.interval) {
219
163
  listener(e.detail);
220
- });
221
- }
222
- /**
223
- * Subscribe to L2 order book updates for a specific asset.
224
- * @param args - The parameters for the subscription.
225
- * @param listener - The callback function to be called when the event is received.
226
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
227
- *
228
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
229
- * @example
230
- * ```ts
231
- * import * as hl from "@nktkas/hyperliquid";
232
- *
233
- * const transport = new hl.WebSocketTransport();
234
- * const subsClient = new hl.SubscriptionClient({ transport });
235
- *
236
- * const sub = await subsClient.l2Book({ coin: "BTC" }, (data) => {
237
- * console.log(data);
238
- * });
239
- * ```
240
- */
241
- l2Book(args, listener) {
242
- const payload = {
243
- type: "l2Book",
244
- coin: args.coin,
245
- nSigFigs: args.nSigFigs ?? null,
246
- mantissa: args.mantissa ?? null,
247
- };
248
- return this.transport.subscribe(payload.type, payload, (e) => {
249
- if (e.detail.coin === args.coin) {
250
- listener(e.detail);
251
- }
252
- });
253
- }
254
- /**
255
- * Subscribe to notification updates for a specific user.
256
- * @param args - The parameters for the subscription.
257
- * @param listener - The callback function to be called when the event is received.
258
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
259
- *
260
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
261
- * @example
262
- * ```ts
263
- * import * as hl from "@nktkas/hyperliquid";
264
- *
265
- * const transport = new hl.WebSocketTransport();
266
- * const subsClient = new hl.SubscriptionClient({ transport });
267
- *
268
- * const sub = await subsClient.notification({ user: "0x..." }, (data) => {
269
- * console.log(data);
270
- * });
271
- * ```
272
- */
273
- notification(args, listener) {
274
- const payload = {
275
- type: "notification",
276
- user: args.user,
277
- };
278
- return this.transport.subscribe(payload.type, payload, (e) => {
164
+ }
165
+ });
166
+ }
167
+ /**
168
+ * Subscribe to explorer block updates.
169
+ * @param listener - The callback function to be called when the event is received.
170
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
171
+ * @note Make sure the endpoint in the {@link transport} supports this method.
172
+ *
173
+ * @throws {TransportError} When the transport layer throws an error.
174
+ *
175
+ * @see null
176
+ * @example
177
+ * ```ts
178
+ * import * as hl from "@nktkas/hyperliquid";
179
+ *
180
+ * const transport = new hl.WebSocketTransport();
181
+ * const subsClient = new hl.SubscriptionClient({ transport });
182
+ *
183
+ * const sub = await subsClient.explorerBlock((data) => {
184
+ * console.log(data);
185
+ * });
186
+ * ```
187
+ */
188
+ explorerBlock(listener) {
189
+ const payload = {
190
+ type: "explorerBlock",
191
+ };
192
+ return this.transport.subscribe("_explorerBlock", payload, (e) => {
193
+ listener(e.detail);
194
+ });
195
+ }
196
+ /**
197
+ * Subscribe to explorer transaction updates.
198
+ * @param listener - The callback function to be called when the event is received.
199
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
200
+ * @note Make sure the endpoint in the {@link transport} supports this method.
201
+ *
202
+ * @throws {TransportError} When the transport layer throws an error.
203
+ *
204
+ * @see null
205
+ * @example
206
+ * ```ts
207
+ * import * as hl from "@nktkas/hyperliquid";
208
+ *
209
+ * const transport = new hl.WebSocketTransport();
210
+ * const subsClient = new hl.SubscriptionClient({ transport });
211
+ *
212
+ * const sub = await subsClient.explorerTxs((data) => {
213
+ * console.log(data);
214
+ * });
215
+ * ```
216
+ */
217
+ explorerTxs(listener) {
218
+ const payload = {
219
+ type: "explorerTxs",
220
+ };
221
+ return this.transport.subscribe("_explorerTxs", payload, (e) => {
222
+ listener(e.detail);
223
+ });
224
+ }
225
+ /**
226
+ * Subscribe to L2 order book updates for a specific asset.
227
+ * @param args - The parameters for the subscription.
228
+ * @param listener - The callback function to be called when the event is received.
229
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
230
+ *
231
+ * @throws {TransportError} When the transport layer throws an error.
232
+ *
233
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
234
+ * @example
235
+ * ```ts
236
+ * import * as hl from "@nktkas/hyperliquid";
237
+ *
238
+ * const transport = new hl.WebSocketTransport();
239
+ * const subsClient = new hl.SubscriptionClient({ transport });
240
+ *
241
+ * const sub = await subsClient.l2Book({ coin: "BTC" }, (data) => {
242
+ * console.log(data);
243
+ * });
244
+ * ```
245
+ */
246
+ l2Book(args, listener) {
247
+ const payload = {
248
+ type: "l2Book",
249
+ coin: args.coin,
250
+ nSigFigs: args.nSigFigs ?? null,
251
+ mantissa: args.mantissa ?? null,
252
+ };
253
+ return this.transport.subscribe(payload.type, payload, (e) => {
254
+ if (e.detail.coin === args.coin) {
279
255
  listener(e.detail);
280
- });
281
- }
282
- /**
283
- * Subscribe to order status updates for a specific user.
284
- * @param args - The parameters for the subscription.
285
- * @param listener - The callback function to be called when the event is received.
286
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
287
- *
288
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
289
- * @example
290
- * ```ts
291
- * import * as hl from "@nktkas/hyperliquid";
292
- *
293
- * const transport = new hl.WebSocketTransport();
294
- * const subsClient = new hl.SubscriptionClient({ transport });
295
- *
296
- * const sub = await subsClient.orderUpdates({ user: "0x..." }, (data) => {
297
- * console.log(data);
298
- * });
299
- * ```
300
- */
301
- orderUpdates(args, listener) {
302
- const payload = {
303
- type: "orderUpdates",
304
- user: args.user,
305
- };
306
- return this.transport.subscribe(payload.type, payload, (e) => {
256
+ }
257
+ });
258
+ }
259
+ /**
260
+ * Subscribe to notification updates for a specific user.
261
+ * @param args - The parameters for the subscription.
262
+ * @param listener - The callback function to be called when the event is received.
263
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
264
+ *
265
+ * @throws {TransportError} When the transport layer throws an error.
266
+ *
267
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
268
+ * @example
269
+ * ```ts
270
+ * import * as hl from "@nktkas/hyperliquid";
271
+ *
272
+ * const transport = new hl.WebSocketTransport();
273
+ * const subsClient = new hl.SubscriptionClient({ transport });
274
+ *
275
+ * const sub = await subsClient.notification({ user: "0x..." }, (data) => {
276
+ * console.log(data);
277
+ * });
278
+ * ```
279
+ */
280
+ notification(args, listener) {
281
+ const payload = {
282
+ type: "notification",
283
+ user: args.user,
284
+ };
285
+ return this.transport.subscribe(payload.type, payload, (e) => {
286
+ listener(e.detail);
287
+ });
288
+ }
289
+ /**
290
+ * Subscribe to order status updates for a specific user.
291
+ * @param args - The parameters for the subscription.
292
+ * @param listener - The callback function to be called when the event is received.
293
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
294
+ *
295
+ * @throws {TransportError} When the transport layer throws an error.
296
+ *
297
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
298
+ * @example
299
+ * ```ts
300
+ * import * as hl from "@nktkas/hyperliquid";
301
+ *
302
+ * const transport = new hl.WebSocketTransport();
303
+ * const subsClient = new hl.SubscriptionClient({ transport });
304
+ *
305
+ * const sub = await subsClient.orderUpdates({ user: "0x..." }, (data) => {
306
+ * console.log(data);
307
+ * });
308
+ * ```
309
+ */
310
+ orderUpdates(args, listener) {
311
+ const payload = {
312
+ type: "orderUpdates",
313
+ user: args.user,
314
+ };
315
+ return this.transport.subscribe(payload.type, payload, (e) => {
316
+ listener(e.detail);
317
+ });
318
+ }
319
+ /**
320
+ * Subscribe to real-time trade updates for a specific asset.
321
+ * @param args - The parameters for the subscription.
322
+ * @param listener - The callback function to be called when the event is received.
323
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
324
+ *
325
+ * @throws {TransportError} When the transport layer throws an error.
326
+ *
327
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
328
+ * @example
329
+ * ```ts
330
+ * import * as hl from "@nktkas/hyperliquid";
331
+ *
332
+ * const transport = new hl.WebSocketTransport();
333
+ * const subsClient = new hl.SubscriptionClient({ transport });
334
+ *
335
+ * const sub = await subsClient.trades({ coin: "BTC" }, (data) => {
336
+ * console.log(data);
337
+ * });
338
+ * ```
339
+ */
340
+ trades(args, listener) {
341
+ const payload = {
342
+ type: "trades",
343
+ coin: args.coin,
344
+ };
345
+ return this.transport.subscribe(payload.type, payload, (e) => {
346
+ if (e.detail[0]?.coin === args.coin) {
347
+ listener(e.detail);
348
+ }
349
+ });
350
+ }
351
+ /**
352
+ * Subscribe to non-order events for a specific user.
353
+ * @param args - The parameters for the subscription.
354
+ * @param listener - The callback function to be called when the event is received.
355
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
356
+ * @note Different subscriptions cannot be distinguished from each other.
357
+ *
358
+ * @throws {TransportError} When the transport layer throws an error.
359
+ *
360
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
361
+ * @example
362
+ * ```ts
363
+ * import * as hl from "@nktkas/hyperliquid";
364
+ *
365
+ * const transport = new hl.WebSocketTransport();
366
+ * const subsClient = new hl.SubscriptionClient({ transport });
367
+ *
368
+ * const sub = await subsClient.userEvents({ user: "0x..." }, (data) => {
369
+ * console.log(data);
370
+ * });
371
+ * ```
372
+ */
373
+ userEvents(args, listener) {
374
+ const payload = {
375
+ type: "userEvents",
376
+ user: args.user,
377
+ };
378
+ return this.transport.subscribe("user", payload, (e) => {
379
+ listener(e.detail);
380
+ });
381
+ }
382
+ /**
383
+ * Subscribe to trade fill updates for a specific user.
384
+ * @param args - The parameters for the subscription.
385
+ * @param listener - The callback function to be called when the event is received.
386
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
387
+ *
388
+ * @throws {TransportError} When the transport layer throws an error.
389
+ *
390
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
391
+ * @example
392
+ * ```ts
393
+ * import * as hl from "@nktkas/hyperliquid";
394
+ *
395
+ * const transport = new hl.WebSocketTransport();
396
+ * const subsClient = new hl.SubscriptionClient({ transport });
397
+ *
398
+ * const sub = await subsClient.userFills({ user: "0x..." }, (data) => {
399
+ * console.log(data);
400
+ * });
401
+ * ```
402
+ */
403
+ userFills(args, listener) {
404
+ const payload = {
405
+ type: "userFills",
406
+ user: args.user,
407
+ aggregateByTime: args.aggregateByTime ?? false,
408
+ };
409
+ return this.transport.subscribe(payload.type, payload, (e) => {
410
+ if (e.detail.user === args.user.toLowerCase()) {
411
+ listener(e.detail);
412
+ }
413
+ });
414
+ }
415
+ /**
416
+ * Subscribe to funding payment updates for a specific user.
417
+ * @param args - The parameters for the subscription.
418
+ * @param listener - The callback function to be called when the event is received.
419
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
420
+ *
421
+ * @throws {TransportError} When the transport layer throws an error.
422
+ *
423
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
424
+ * @example
425
+ * ```ts
426
+ * import * as hl from "@nktkas/hyperliquid";
427
+ *
428
+ * const transport = new hl.WebSocketTransport();
429
+ * const subsClient = new hl.SubscriptionClient({ transport });
430
+ *
431
+ * const sub = await subsClient.userFundings({ user: "0x..." }, (data) => {
432
+ * console.log(data);
433
+ * });
434
+ * ```
435
+ */
436
+ userFundings(args, listener) {
437
+ const payload = {
438
+ type: "userFundings",
439
+ user: args.user,
440
+ };
441
+ return this.transport.subscribe(payload.type, payload, (e) => {
442
+ if (e.detail.user === args.user.toLowerCase()) {
443
+ listener(e.detail);
444
+ }
445
+ });
446
+ }
447
+ /**
448
+ * Subscribe to non-funding ledger updates for a specific user.
449
+ * @param args - The parameters for the subscription.
450
+ * @param listener - The callback function to be called when the event is received.
451
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
452
+ *
453
+ * @throws {TransportError} When the transport layer throws an error.
454
+ *
455
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
456
+ * @example
457
+ * ```ts
458
+ * import * as hl from "@nktkas/hyperliquid";
459
+ *
460
+ * const transport = new hl.WebSocketTransport();
461
+ * const subsClient = new hl.SubscriptionClient({ transport });
462
+ *
463
+ * const sub = await subsClient.userNonFundingLedgerUpdates({ user: "0x..." }, (data) => {
464
+ * console.log(data);
465
+ * });
466
+ * ```
467
+ */
468
+ userNonFundingLedgerUpdates(args, listener) {
469
+ const payload = {
470
+ type: "userNonFundingLedgerUpdates",
471
+ user: args.user,
472
+ };
473
+ return this.transport.subscribe(payload.type, payload, (e) => {
474
+ if (e.detail.user === args.user.toLowerCase()) {
475
+ listener(e.detail);
476
+ }
477
+ });
478
+ }
479
+ /**
480
+ * Subscribe to TWAP order history updates for a specific user.
481
+ * @param args - The parameters for the subscription.
482
+ * @param listener - The callback function to be called when the event is received.
483
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
484
+ *
485
+ * @throws {TransportError} When the transport layer throws an error.
486
+ *
487
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
488
+ * @example
489
+ * ```ts
490
+ * import * as hl from "@nktkas/hyperliquid";
491
+ *
492
+ * const transport = new hl.WebSocketTransport();
493
+ * const subsClient = new hl.SubscriptionClient({ transport });
494
+ *
495
+ * const sub = await subsClient.userTwapHistory({ user: "0x..." }, (data) => {
496
+ * console.log(data);
497
+ * });
498
+ * ```
499
+ */
500
+ userTwapHistory(args, listener) {
501
+ const payload = {
502
+ type: "userTwapHistory",
503
+ user: args.user,
504
+ };
505
+ return this.transport.subscribe(payload.type, payload, (e) => {
506
+ if (e.detail.user === args.user.toLowerCase()) {
507
+ listener(e.detail);
508
+ }
509
+ });
510
+ }
511
+ /**
512
+ * Subscribe to TWAP execution updates for a specific user.
513
+ * @param args - The parameters for the subscription.
514
+ * @param listener - The callback function to be called when the event is received.
515
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
516
+ *
517
+ * @throws {TransportError} When the transport layer throws an error.
518
+ *
519
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
520
+ * @example
521
+ * ```ts
522
+ * import * as hl from "@nktkas/hyperliquid";
523
+ *
524
+ * const transport = new hl.WebSocketTransport();
525
+ * const subsClient = new hl.SubscriptionClient({ transport });
526
+ *
527
+ * const sub = await subsClient.userTwapSliceFills({ user: "0x..." }, (data) => {
528
+ * console.log(data);
529
+ * });
530
+ * ```
531
+ */
532
+ userTwapSliceFills(args, listener) {
533
+ const payload = {
534
+ type: "userTwapSliceFills",
535
+ user: args.user,
536
+ };
537
+ return this.transport.subscribe(payload.type, payload, (e) => {
538
+ if (e.detail.user === args.user.toLowerCase()) {
307
539
  listener(e.detail);
308
- });
309
- }
310
- /**
311
- * Subscribe to real-time trade updates for a specific asset.
312
- * @param args - The parameters for the subscription.
313
- * @param listener - The callback function to be called when the event is received.
314
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
315
- *
316
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
317
- * @example
318
- * ```ts
319
- * import * as hl from "@nktkas/hyperliquid";
320
- *
321
- * const transport = new hl.WebSocketTransport();
322
- * const subsClient = new hl.SubscriptionClient({ transport });
323
- *
324
- * const sub = await subsClient.trades({ coin: "BTC" }, (data) => {
325
- * console.log(data);
326
- * });
327
- * ```
328
- */
329
- trades(args, listener) {
330
- const payload = {
331
- type: "trades",
332
- coin: args.coin,
333
- };
334
- return this.transport.subscribe(payload.type, payload, (e) => {
335
- if (e.detail[0]?.coin === args.coin) {
336
- listener(e.detail);
337
- }
338
- });
339
- }
340
- /**
341
- * Subscribe to non-order events for a specific user.
342
- * @param args - The parameters for the subscription.
343
- * @param listener - The callback function to be called when the event is received.
344
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
345
- *
346
- * @note Different subscriptions cannot be distinguished from each other.
347
- *
348
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
349
- * @example
350
- * ```ts
351
- * import * as hl from "@nktkas/hyperliquid";
352
- *
353
- * const transport = new hl.WebSocketTransport();
354
- * const subsClient = new hl.SubscriptionClient({ transport });
355
- *
356
- * const sub = await subsClient.userEvents({ user: "0x..." }, (data) => {
357
- * console.log(data);
358
- * });
359
- * ```
360
- */
361
- userEvents(args, listener) {
362
- const payload = {
363
- type: "userEvents",
364
- user: args.user,
365
- };
366
- return this.transport.subscribe("user", payload, (e) => {
540
+ }
541
+ });
542
+ }
543
+ /**
544
+ * Subscribe to comprehensive user and market data updates.
545
+ * @param args - The parameters for the subscription.
546
+ * @param listener - The callback function to be called when the event is received.
547
+ * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
548
+ *
549
+ * @throws {TransportError} When the transport layer throws an error.
550
+ *
551
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
552
+ * @example
553
+ * ```ts
554
+ * import * as hl from "@nktkas/hyperliquid";
555
+ *
556
+ * const transport = new hl.WebSocketTransport();
557
+ * const subsClient = new hl.SubscriptionClient({ transport });
558
+ *
559
+ * const sub = await subsClient.webData2({ user: "0x..." }, (data) => {
560
+ * console.log(data);
561
+ * });
562
+ * ```
563
+ */
564
+ webData2(args, listener) {
565
+ const payload = {
566
+ type: "webData2",
567
+ user: args.user,
568
+ };
569
+ return this.transport.subscribe(payload.type, payload, (e) => {
570
+ if (e.detail.user === args.user.toLowerCase()) {
367
571
  listener(e.detail);
368
- });
369
- }
370
- /**
371
- * Subscribe to trade fill updates for a specific user.
372
- * @param args - The parameters for the subscription.
373
- * @param listener - The callback function to be called when the event is received.
374
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
375
- *
376
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
377
- * @example
378
- * ```ts
379
- * import * as hl from "@nktkas/hyperliquid";
380
- *
381
- * const transport = new hl.WebSocketTransport();
382
- * const subsClient = new hl.SubscriptionClient({ transport });
383
- *
384
- * const sub = await subsClient.userFills({ user: "0x..." }, (data) => {
385
- * console.log(data);
386
- * });
387
- * ```
388
- */
389
- userFills(args, listener) {
390
- const payload = {
391
- type: "userFills",
392
- user: args.user,
393
- aggregateByTime: args.aggregateByTime ?? false,
394
- };
395
- return this.transport.subscribe(payload.type, payload, (e) => {
396
- if (e.detail.user === args.user.toLowerCase()) {
397
- listener(e.detail);
398
- }
399
- });
400
- }
401
- /**
402
- * Subscribe to funding payment updates for a specific user.
403
- * @param args - The parameters for the subscription.
404
- * @param listener - The callback function to be called when the event is received.
405
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
406
- *
407
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
408
- * @example
409
- * ```ts
410
- * import * as hl from "@nktkas/hyperliquid";
411
- *
412
- * const transport = new hl.WebSocketTransport();
413
- * const subsClient = new hl.SubscriptionClient({ transport });
414
- *
415
- * const sub = await subsClient.userFundings({ user: "0x..." }, (data) => {
416
- * console.log(data);
417
- * });
418
- * ```
419
- */
420
- userFundings(args, listener) {
421
- const payload = {
422
- type: "userFundings",
423
- user: args.user,
424
- };
425
- return this.transport.subscribe(payload.type, payload, (e) => {
426
- if (e.detail.user === args.user.toLowerCase()) {
427
- listener(e.detail);
428
- }
429
- });
430
- }
431
- /**
432
- * Subscribe to non-funding ledger updates for a specific user.
433
- * @param args - The parameters for the subscription.
434
- * @param listener - The callback function to be called when the event is received.
435
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
436
- *
437
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
438
- * @example
439
- * ```ts
440
- * import * as hl from "@nktkas/hyperliquid";
441
- *
442
- * const transport = new hl.WebSocketTransport();
443
- * const subsClient = new hl.SubscriptionClient({ transport });
444
- *
445
- * const sub = await subsClient.userNonFundingLedgerUpdates({ user: "0x..." }, (data) => {
446
- * console.log(data);
447
- * });
448
- * ```
449
- */
450
- userNonFundingLedgerUpdates(args, listener) {
451
- const payload = {
452
- type: "userNonFundingLedgerUpdates",
453
- user: args.user,
454
- };
455
- return this.transport.subscribe(payload.type, payload, (e) => {
456
- if (e.detail.user === args.user.toLowerCase()) {
457
- listener(e.detail);
458
- }
459
- });
460
- }
461
- /**
462
- * Subscribe to TWAP order history updates for a specific user.
463
- * @param args - The parameters for the subscription.
464
- * @param listener - The callback function to be called when the event is received.
465
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
466
- *
467
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
468
- * @example
469
- * ```ts
470
- * import * as hl from "@nktkas/hyperliquid";
471
- *
472
- * const transport = new hl.WebSocketTransport();
473
- * const subsClient = new hl.SubscriptionClient({ transport });
474
- *
475
- * const sub = await subsClient.userTwapHistory({ user: "0x..." }, (data) => {
476
- * console.log(data);
477
- * });
478
- * ```
479
- */
480
- userTwapHistory(args, listener) {
481
- const payload = {
482
- type: "userTwapHistory",
483
- user: args.user,
484
- };
485
- return this.transport.subscribe(payload.type, payload, (e) => {
486
- if (e.detail.user === args.user.toLowerCase()) {
487
- listener(e.detail);
488
- }
489
- });
490
- }
491
- /**
492
- * Subscribe to TWAP execution updates for a specific user.
493
- * @param args - The parameters for the subscription.
494
- * @param listener - The callback function to be called when the event is received.
495
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
496
- *
497
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
498
- * @example
499
- * ```ts
500
- * import * as hl from "@nktkas/hyperliquid";
501
- *
502
- * const transport = new hl.WebSocketTransport();
503
- * const subsClient = new hl.SubscriptionClient({ transport });
504
- *
505
- * const sub = await subsClient.userTwapSliceFills({ user: "0x..." }, (data) => {
506
- * console.log(data);
507
- * });
508
- * ```
509
- */
510
- userTwapSliceFills(args, listener) {
511
- const payload = {
512
- type: "userTwapSliceFills",
513
- user: args.user,
514
- };
515
- return this.transport.subscribe(payload.type, payload, (e) => {
516
- if (e.detail.user === args.user.toLowerCase()) {
517
- listener(e.detail);
518
- }
519
- });
520
- }
521
- /**
522
- * Subscribe to comprehensive user and market data updates.
523
- * @param args - The parameters for the subscription.
524
- * @param listener - The callback function to be called when the event is received.
525
- * @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
526
- *
527
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
528
- * @example
529
- * ```ts
530
- * import * as hl from "@nktkas/hyperliquid";
531
- *
532
- * const transport = new hl.WebSocketTransport();
533
- * const subsClient = new hl.SubscriptionClient({ transport });
534
- *
535
- * const sub = await subsClient.webData2({ user: "0x..." }, (data) => {
536
- * console.log(data);
537
- * });
538
- * ```
539
- */
540
- webData2(args, listener) {
541
- const payload = {
542
- type: "webData2",
543
- user: args.user,
544
- };
545
- return this.transport.subscribe(payload.type, payload, (e) => {
546
- if (e.detail.user === args.user.toLowerCase()) {
547
- listener(e.detail);
548
- }
549
- });
550
- }
551
- async [Symbol.asyncDispose]() {
552
- await this.transport[Symbol.asyncDispose]?.();
553
- }
572
+ }
573
+ });
574
+ }
575
+ async [Symbol.asyncDispose]() {
576
+ await this.transport[Symbol.asyncDispose]?.();
554
577
  }
555
- exports.SubscriptionClient = SubscriptionClient;
556
- });
578
+ }
579
+ exports.SubscriptionClient = SubscriptionClient;