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