@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.
- package/LICENSE +20 -20
- package/README.md +33 -17
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
- package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
- package/esm/mod.d.ts +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/clients/event.d.ts +57 -16
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +72 -16
- package/esm/src/clients/public.d.ts +241 -49
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +243 -47
- package/esm/src/clients/wallet.d.ts +120 -51
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +192 -58
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.js +3 -3
- package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +41 -35
- package/esm/src/types/exchange/common.d.ts +6 -6
- package/esm/src/types/exchange/common.d.ts.map +1 -1
- package/esm/src/types/exchange/requests.d.ts +131 -64
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +7 -7
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/common.d.ts +15 -15
- package/esm/src/types/explorer/common.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +19 -6
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +9 -2
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +189 -124
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +82 -78
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +117 -0
- package/esm/src/types/info/delegations.d.ts.map +1 -0
- package/esm/src/types/info/delegations.js +1 -0
- package/esm/src/types/info/orders.d.ts +67 -67
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +128 -63
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +41 -84
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/subscriptions/common.d.ts +3 -0
- package/esm/src/types/subscriptions/common.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +10 -0
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/utils/key_sort.d.ts +2 -2
- package/esm/src/utils/key_sort.d.ts.map +1 -1
- package/esm/src/utils/signing.d.ts +1 -1
- package/esm/src/utils/signing.js +2 -2
- package/package.json +1 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
- package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
- package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
- package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
- package/script/mod.d.ts +1 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +23 -13
- package/script/src/clients/event.d.ts +57 -16
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +551 -485
- package/script/src/clients/public.d.ts +241 -49
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +914 -708
- package/script/src/clients/wallet.d.ts +120 -51
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +1121 -977
- package/script/src/transports/base.js +25 -15
- package/script/src/transports/http/http_transport.js +174 -164
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
- package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
- package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
- package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +236 -220
- package/script/src/types/common.js +12 -2
- package/script/src/types/exchange/common.d.ts +6 -6
- package/script/src/types/exchange/common.d.ts.map +1 -1
- package/script/src/types/exchange/common.js +12 -2
- package/script/src/types/exchange/requests.d.ts +131 -64
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +12 -2
- package/script/src/types/exchange/responses.d.ts +7 -7
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/exchange/responses.js +12 -2
- package/script/src/types/explorer/common.d.ts +15 -15
- package/script/src/types/explorer/common.d.ts.map +1 -1
- package/script/src/types/explorer/common.js +12 -2
- package/script/src/types/explorer/requests.d.ts +19 -6
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +12 -2
- package/script/src/types/explorer/responses.d.ts +9 -2
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/explorer/responses.js +12 -2
- package/script/src/types/info/accounts.d.ts +189 -124
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +12 -2
- package/script/src/types/info/assets.d.ts +82 -78
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/assets.js +12 -2
- package/script/src/types/info/delegations.d.ts +117 -0
- package/script/src/types/info/delegations.d.ts.map +1 -0
- package/script/src/types/info/delegations.js +12 -0
- package/script/src/types/info/orders.d.ts +67 -67
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +12 -2
- package/script/src/types/info/requests.d.ts +128 -63
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +12 -2
- package/script/src/types/info/vaults.d.ts +41 -84
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +12 -2
- package/script/src/types/subscriptions/common.d.ts +3 -0
- package/script/src/types/subscriptions/common.d.ts.map +1 -1
- package/script/src/types/subscriptions/common.js +12 -2
- package/script/src/types/subscriptions/requests.d.ts +10 -0
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +12 -2
- package/script/src/utils/key_sort.d.ts +2 -2
- package/script/src/utils/key_sort.d.ts.map +1 -1
- package/script/src/utils/key_sort.js +133 -123
- package/script/src/utils/signing.d.ts +1 -1
- package/script/src/utils/signing.js +172 -162
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
- /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
- /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
|
|
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
|
|
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
|
|
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
|
|
52
|
-
* - Value: Subscription info containing
|
|
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
|
-
|
|
56
|
-
|
|
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
|
|
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
|
|
37
|
-
* - Value: Subscription info containing
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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 = {
|
|
143
|
+
subscriptionInfo = { listeners: new Map(), requestPromise };
|
|
139
144
|
this._subscriptions.set(id, subscriptionInfo);
|
|
140
145
|
}
|
|
141
|
-
//
|
|
142
|
-
let
|
|
143
|
-
if (!
|
|
144
|
-
// Create new unsubscribe function
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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 {
|
|
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
|
|
5
|
-
/**
|
|
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
|
|
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
|
|
25
|
+
/** Is market order? */
|
|
26
26
|
isMarket: boolean;
|
|
27
27
|
/** Trigger price. */
|
|
28
28
|
triggerPx: string;
|
|
29
|
-
/** Indicates
|
|
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,
|
|
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"}
|