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