@nktkas/hyperliquid 0.13.1 → 0.13.2

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