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