@nktkas/hyperliquid 0.19.2 → 0.21.0

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