@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
@@ -65,19 +65,19 @@ export class WebSocketRequestDispatcher {
65
65
  const parsedRequest = JSON.parse(request);
66
66
  if ("id" in parsedRequest && typeof parsedRequest.id === "number") {
67
67
  // If a post request was sent, it is possible to get the id from the request
68
- this.reject(parsedRequest.id, new WebSocketRequestError(`Cannot process WebSocket request: ${event.detail}`));
68
+ this.reject(parsedRequest.id, new WebSocketRequestError(`Cannot complete WebSocket request: ${event.detail}`));
69
69
  }
70
70
  else if ("subscription" in parsedRequest &&
71
71
  typeof parsedRequest.subscription === "object" &&
72
72
  parsedRequest.subscription !== null) {
73
73
  // If a subscription/unsubscribe request was sent, use the request as an id
74
74
  const id = WebSocketRequestDispatcher.requestToId(parsedRequest.subscription);
75
- this.reject(id, new WebSocketRequestError(`Cannot process subscription request: ${event.detail}`));
75
+ this.reject(id, new WebSocketRequestError(`Cannot complete WebSocket request: ${event.detail}`));
76
76
  }
77
77
  else {
78
78
  // If the request is not recognized, use the parsed request as an id
79
79
  const id = WebSocketRequestDispatcher.requestToId(parsedRequest);
80
- this.reject(id, new WebSocketRequestError(`Cannot process unrecognized request: ${event.detail}`));
80
+ this.reject(id, new WebSocketRequestError(`Cannot complete WebSocket request: ${event.detail}`));
81
81
  }
82
82
  }
83
83
  }
@@ -48,12 +48,15 @@ export declare class WebSocketTransport implements IRequestTransport, ISubscript
48
48
  protected _hlEvents: HyperliquidEventTarget;
49
49
  /**
50
50
  * Map of active subscriptions.
51
- * - Key: Unique subscription identifier (stringified payload)
52
- * - Value: Subscription info containing payload and listener mappings
51
+ * - Key: Unique subscription identifier based on payload
52
+ * - Value: Subscription info containing the subscription request promise
53
+ * and a map of listeners to their metadata (channel + unsubscribe function).
53
54
  */
54
55
  protected _subscriptions: Map<string, {
55
- channel: string;
56
- listeners: Map<(data: CustomEvent) => void, () => Promise<void>>;
56
+ listeners: Map<(data: CustomEvent) => void, {
57
+ channel: string;
58
+ unsubscribe: (signal?: AbortSignal) => Promise<void>;
59
+ }>;
57
60
  requestPromise: Promise<unknown>;
58
61
  }>;
59
62
  /**
@@ -107,11 +110,5 @@ export declare class WebSocketTransport implements IRequestTransport, ISubscript
107
110
  * @returns A promise that resolves when the connection is fully closed.
108
111
  */
109
112
  close(signal?: AbortSignal): Promise<void>;
110
- /**
111
- * Combines timeout and user-provided signal.
112
- * @param signal - A user-provided signal.
113
- * @returns An AbortSignal that triggers when either the timeout or user-provided signal aborts.
114
- */
115
- protected combineSignals(signal?: AbortSignal): AbortSignal;
116
113
  }
117
114
  //# sourceMappingURL=websocket_transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE;QACR;;;;WAIG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,iBAAiB,EAAE,sBAAsB;IAChF,qDAAqD;IACrD,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,iDAAiD;IACjD,SAAS,CAAC,YAAY,EAAE,0BAA0B,CAAC;IAEnD,6CAA6C;IAC7C,SAAS,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAE5C;;;;OAIG;IACH,SAAS,CAAC,cAAc,EAAE,GAAG,CACzB,MAAM,EACN;QACI,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;KACpC,CACJ,CAUG;IAEJ;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE;QAChB;;;WAGG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACpC,CAAC;IAEF,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IAEvC;;;OAGG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAwC/C;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvG;;;;;;;OAOG;IACG,SAAS,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EACrC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAqDxB;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB1C;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB1C;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW;CAM9D"}
1
+ {"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,KAAK,4BAA4B,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE;QACR;;;;WAIG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,iBAAiB,EAAE,sBAAsB;IAChF,qDAAqD;IACrD,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9C,iDAAiD;IACjD,SAAS,CAAC,YAAY,EAAE,0BAA0B,CAAC;IAEnD,6CAA6C;IAC7C,SAAS,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAE5C;;;;;OAKG;IACH,SAAS,CAAC,cAAc,EAAE,GAAG,CACzB,MAAM,EACN;QACI,SAAS,EAAE,GAAG,CACV,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EAC3B;YACI,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;SACxD,CACJ,CAAC;QACF,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;KACpC,CACJ,CAAa;IAEd;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,EAAE;QAChB;;;WAGG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;KACpC,CAAC;IAEF,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC;IAEvC;;;OAGG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAwC/C;;;;;;;;OAQG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAevG;;;;;;;OAOG;IACG,SAAS,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,EACrC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAwExB;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB1C;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAoB7C"}
@@ -33,8 +33,9 @@ export class WebSocketTransport {
33
33
  });
34
34
  /**
35
35
  * Map of active subscriptions.
36
- * - Key: Unique subscription identifier (stringified payload)
37
- * - Value: Subscription info containing payload and listener mappings
36
+ * - Key: Unique subscription identifier based on payload
37
+ * - Value: Subscription info containing the subscription request promise
38
+ * and a map of listeners to their metadata (channel + unsubscribe function).
38
39
  */
39
40
  Object.defineProperty(this, "_subscriptions", {
40
41
  enumerable: true,
@@ -89,8 +90,8 @@ export class WebSocketTransport {
89
90
  this._keepAliveTimer = undefined;
90
91
  }
91
92
  // Clear all subscriptions
92
- for (const [_, { channel, listeners }] of this._subscriptions.entries()) {
93
- for (const [listener] of listeners) {
93
+ for (const subscriptionInfo of this._subscriptions.values()) {
94
+ for (const [listener, { channel }] of subscriptionInfo.listeners) {
94
95
  this._hlEvents.removeEventListener(channel, listener);
95
96
  }
96
97
  }
@@ -112,7 +113,11 @@ export class WebSocketTransport {
112
113
  throw new Error("Explorer requests are not supported in the Hyperliquid WebSocket API.");
113
114
  }
114
115
  // Send the request and wait for a response
115
- return this._wsRequester.request("post", { type, payload }, this.combineSignals(signal));
116
+ const timeoutSignal = this.timeout ? AbortSignal.timeout(this.timeout) : undefined;
117
+ const combinedSignal = timeoutSignal && signal
118
+ ? AbortSignal.any([timeoutSignal, signal])
119
+ : timeoutSignal ?? signal;
120
+ return this._wsRequester.request("post", { type, payload }, combinedSignal);
116
121
  }
117
122
  /**
118
123
  * Subscribes to a Hyperliquid event channel.
@@ -124,48 +129,62 @@ export class WebSocketTransport {
124
129
  */
125
130
  async subscribe(channel, payload, listener, signal) {
126
131
  // Create a unique identifier for the subscription
127
- const id = `${channel}::${WebSocketRequestDispatcher.requestToId(payload)}`;
132
+ const id = WebSocketRequestDispatcher.requestToId(payload);
128
133
  // Initialize new subscription, if it doesn't exist
129
134
  let subscriptionInfo = this._subscriptions.get(id);
130
135
  if (!subscriptionInfo) {
131
136
  // Send subscription request
132
- const requestPromise = this._wsRequester.request("subscribe", payload, this.combineSignals(signal))
133
- .catch((error) => {
134
- this._subscriptions.delete(id);
135
- throw error;
136
- });
137
+ const timeoutSignal = this.timeout ? AbortSignal.timeout(this.timeout) : undefined;
138
+ const combinedSignal = timeoutSignal && signal
139
+ ? AbortSignal.any([timeoutSignal, signal])
140
+ : timeoutSignal ?? signal;
141
+ const requestPromise = this._wsRequester.request("subscribe", payload, combinedSignal);
137
142
  // Cache subscription info
138
- subscriptionInfo = { channel, listeners: new Map(), requestPromise };
143
+ subscriptionInfo = { listeners: new Map(), requestPromise };
139
144
  this._subscriptions.set(id, subscriptionInfo);
140
145
  }
141
- // Check if we already have an unsubscribe function for this listener
142
- let unsubscribe = subscriptionInfo.listeners.get(listener);
143
- if (!unsubscribe) {
144
- // Create new unsubscribe function if none exists
145
- unsubscribe = async (signal) => {
146
+ // Initialize new listener, if it doesn't exist
147
+ let listenerInfo = subscriptionInfo.listeners.get(listener);
148
+ if (!listenerInfo) {
149
+ // Create new unsubscribe function
150
+ const unsubscribe = async (signal) => {
146
151
  // Remove listener and cleanup
147
152
  this._hlEvents.removeEventListener(channel, listener);
148
153
  const isDeleted = subscriptionInfo.listeners.delete(listener);
149
154
  // If no listeners remain, remove subscription entirely
150
155
  // `isDeleted` means that the map had a listener before and became 0 after that
151
156
  if (subscriptionInfo.listeners.size === 0 && isDeleted) {
157
+ // Cleanup subscription
152
158
  this._subscriptions.delete(id);
153
- await this._wsRequester.request("unsubscribe", payload, this.combineSignals(signal));
159
+ // Send unsubscription request
160
+ const timeoutSignal = this.timeout ? AbortSignal.timeout(this.timeout) : undefined;
161
+ const combinedSignal = timeoutSignal && signal
162
+ ? AbortSignal.any([timeoutSignal, signal])
163
+ : timeoutSignal ?? signal;
164
+ await this._wsRequester.request("unsubscribe", payload, combinedSignal);
154
165
  }
155
166
  };
156
- // Add event listener & Cache unsubscribe function
167
+ // Cache listener info
168
+ listenerInfo = { channel, unsubscribe };
169
+ subscriptionInfo.listeners.set(listener, listenerInfo);
170
+ // Add event listener
157
171
  this._hlEvents.addEventListener(channel, listener);
158
- subscriptionInfo.listeners.set(listener, unsubscribe);
159
172
  }
160
173
  // Wait for the initial subscription request to complete
161
174
  await subscriptionInfo.requestPromise.catch((error) => {
162
- // Cleanup the subscription and rethrow the error
175
+ // Remove listener and cleanup
163
176
  this._hlEvents.removeEventListener(channel, listener);
164
177
  subscriptionInfo.listeners.delete(listener);
178
+ // If no listeners remain, remove subscription entirely
179
+ if (subscriptionInfo.listeners.size === 0)
180
+ this._subscriptions.delete(id);
181
+ // Rethrow the error
165
182
  throw error;
166
183
  });
167
184
  // Return subscription control object
168
- return { unsubscribe };
185
+ return {
186
+ unsubscribe: listenerInfo.unsubscribe,
187
+ };
169
188
  }
170
189
  /**
171
190
  * Waits until the WebSocket connection is ready.
@@ -217,17 +236,4 @@ export class WebSocketTransport {
217
236
  this.socket.close();
218
237
  });
219
238
  }
220
- /**
221
- * Combines timeout and user-provided signal.
222
- * @param signal - A user-provided signal.
223
- * @returns An AbortSignal that triggers when either the timeout or user-provided signal aborts.
224
- */
225
- combineSignals(signal) {
226
- const signals = [];
227
- if (this.timeout)
228
- signals.push(AbortSignal.timeout(this.timeout));
229
- if (signal)
230
- signals.push(signal);
231
- return signals.length > 1 ? AbortSignal.any(signals) : signals[0];
232
- }
233
239
  }
@@ -1,10 +1,10 @@
1
1
  import type { Hex } from "../common.js";
2
2
  import type { TIF } from "../info/orders.js";
3
3
  /** Order parameters. */
4
- export type OrderParms = {
5
- /** An integer representing the asset being traded. */
4
+ export type OrderParams = {
5
+ /** Asset ID. */
6
6
  a: number;
7
- /** Position side (true for long, false for short). */
7
+ /** Position side (`true` for long, `false` for short). */
8
8
  b: boolean;
9
9
  /** Price. */
10
10
  p: string;
@@ -12,7 +12,7 @@ export type OrderParms = {
12
12
  s: string;
13
13
  /** Is reduce-only? */
14
14
  r: boolean;
15
- /** Order type and parameters. */
15
+ /** Order type. */
16
16
  t: {
17
17
  /** Limit order parameters. */
18
18
  limit: {
@@ -22,11 +22,11 @@ export type OrderParms = {
22
22
  } | {
23
23
  /** Trigger order parameters. */
24
24
  trigger: {
25
- /** Is the market order. */
25
+ /** Is market order? */
26
26
  isMarket: boolean;
27
27
  /** Trigger price. */
28
28
  triggerPx: string;
29
- /** Indicates if it's take-profit or stop-loss. */
29
+ /** Indicates whether it is take profit or stop loss. */
30
30
  tpsl: "tp" | "sl";
31
31
  };
32
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/src/types/exchange/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,wBAAwB;AACxB,MAAM,MAAM,UAAU,GAAG;IACrB,sDAAsD;IACtD,CAAC,EAAE,MAAM,CAAC;IAEV,sDAAsD;IACtD,CAAC,EAAE,OAAO,CAAC;IAEX,aAAa;IACb,CAAC,EAAE,MAAM,CAAC;IAEV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IAEV,sBAAsB;IACtB,CAAC,EAAE,OAAO,CAAC;IAEX,iCAAiC;IACjC,CAAC,EACK;QACE,8BAA8B;QAC9B,KAAK,EAAE;YACH,qBAAqB;YACrB,GAAG,EAAE,GAAG,CAAC;SACZ,CAAC;KACL,GACC;QACE,gCAAgC;QAChC,OAAO,EAAE;YACL,2BAA2B;YAC3B,QAAQ,EAAE,OAAO,CAAC;YAElB,qBAAqB;YACrB,SAAS,EAAE,MAAM,CAAC;YAElB,kDAAkD;YAClD,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;SACrB,CAAC;KACL,CAAC;IAEN,uBAAuB;IACvB,CAAC,CAAC,EAAE,GAAG,CAAC;CACX,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/src/types/exchange/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C,wBAAwB;AACxB,MAAM,MAAM,WAAW,GAAG;IACtB,gBAAgB;IAChB,CAAC,EAAE,MAAM,CAAC;IACV,0DAA0D;IAC1D,CAAC,EAAE,OAAO,CAAC;IACX,aAAa;IACb,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,sBAAsB;IACtB,CAAC,EAAE,OAAO,CAAC;IACX,kBAAkB;IAClB,CAAC,EACK;QACE,8BAA8B;QAC9B,KAAK,EAAE;YACH,qBAAqB;YACrB,GAAG,EAAE,GAAG,CAAC;SACZ,CAAC;KACL,GACC;QACE,gCAAgC;QAChC,OAAO,EAAE;YACL,uBAAuB;YACvB,QAAQ,EAAE,OAAO,CAAC;YAClB,qBAAqB;YACrB,SAAS,EAAE,MAAM,CAAC;YAClB,wDAAwD;YACxD,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;SACrB,CAAC;KACL,CAAC;IACN,uBAAuB;IACvB,CAAC,CAAC,EAAE,GAAG,CAAC;CACX,CAAC"}