@nktkas/hyperliquid 0.19.2 → 0.20.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 +21 -29
- package/esm/_dnt.polyfills.d.ts +20 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +12 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- 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/esm/src/clients/event.d.ts +2 -3
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +49 -57
- package/esm/src/clients/public.d.ts +24 -5
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +23 -7
- package/esm/src/clients/wallet.d.ts +12 -13
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +55 -265
- package/esm/src/signing.d.ts +5 -0
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +24 -5
- package/esm/src/transports/base.d.ts +49 -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 +18 -25
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +80 -179
- package/{script/src/transports/websocket/_websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/esm/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +41 -74
- package/esm/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +61 -76
- 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 +4 -0
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +3 -1
- package/package.json +12 -9
- package/script/_dnt.polyfills.d.ts +20 -0
- package/script/_dnt.polyfills.d.ts.map +1 -0
- package/script/_dnt.polyfills.js +23 -0
- package/script/mod.d.ts +3 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +3 -1
- 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/script/src/clients/event.d.ts +2 -3
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +49 -57
- package/script/src/clients/public.d.ts +24 -5
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +23 -7
- package/script/src/clients/wallet.d.ts +12 -13
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +55 -265
- package/script/src/signing.d.ts +5 -0
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +75 -56
- package/script/src/transports/base.d.ts +49 -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 +18 -25
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +81 -180
- package/{esm/src/transports/websocket/_websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_async_request.d.ts} +14 -18
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/script/src/transports/websocket/{_websocket_request_dispatcher.js → _websocket_async_request.js} +44 -77
- package/script/src/transports/websocket/websocket_transport.d.ts +38 -28
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +63 -78
- 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 +4 -0
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +25 -22
- 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/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
- 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/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -20,21 +20,23 @@ runtimes, written in TypeScript and provided with tests.
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
23
|
+
> [!NOTE]
|
|
24
|
+
> While this library is in TypeScript, it can also be used in JavaScript and there is support for ESM/CommonJS.
|
|
25
|
+
|
|
26
|
+
### Node.js (choose your package manager)
|
|
27
|
+
|
|
23
28
|
```
|
|
24
|
-
# npm
|
|
25
29
|
npm i @nktkas/hyperliquid
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
deno add jsr:@nktkas/hyperliquid
|
|
31
|
+
pnpm add @nktkas/hyperliquid
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
yarn add @nktkas/hyperliquid
|
|
34
|
+
```
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
yarn add jsr:@nktkas/hyperliquid
|
|
36
|
+
### Deno
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
```
|
|
39
|
+
deno add jsr:@nktkas/hyperliquid
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
## Quick Start
|
|
@@ -80,9 +82,7 @@ import * as hl from "@nktkas/hyperliquid";
|
|
|
80
82
|
const transport = new hl.WebSocketTransport();
|
|
81
83
|
const client = new hl.EventClient({ transport });
|
|
82
84
|
|
|
83
|
-
// Subscribe to events
|
|
84
85
|
const sub = await client.allMids((event) => {
|
|
85
|
-
// Handle the event
|
|
86
86
|
console.log(event);
|
|
87
87
|
});
|
|
88
88
|
|
|
@@ -96,7 +96,7 @@ await sub.unsubscribe(); // Unsubscribe from the event
|
|
|
96
96
|
First, choose and configure your transport layer (more details in the [API Reference](#transports)):
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
|
-
import * as hl from "@nktkas/hyperliquid";
|
|
99
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
100
100
|
|
|
101
101
|
// HTTP Transport
|
|
102
102
|
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters
|
|
@@ -112,7 +112,7 @@ Next, initialize a client with the transport layer (more details in the [API Ref
|
|
|
112
112
|
#### Create PublicClient
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
|
-
import * as hl from "@nktkas/hyperliquid";
|
|
115
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
116
116
|
|
|
117
117
|
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
118
118
|
const client = new hl.PublicClient({ transport });
|
|
@@ -121,7 +121,7 @@ const client = new hl.PublicClient({ transport });
|
|
|
121
121
|
#### Create WalletClient
|
|
122
122
|
|
|
123
123
|
```ts
|
|
124
|
-
import * as hl from "@nktkas/hyperliquid";
|
|
124
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
125
125
|
import { createWalletClient, custom } from "viem";
|
|
126
126
|
import { privateKeyToAccount } from "viem/accounts";
|
|
127
127
|
import { ethers } from "ethers";
|
|
@@ -148,7 +148,7 @@ const windowMetamaskClient = new hl.WalletClient({ wallet: window.ethereum, tran
|
|
|
148
148
|
#### Create EventClient
|
|
149
149
|
|
|
150
150
|
```ts
|
|
151
|
-
import * as hl from "@nktkas/hyperliquid";
|
|
151
|
+
import * as hl from "@nktkas/hyperliquid";
|
|
152
152
|
|
|
153
153
|
const transport = new hl.WebSocketTransport(); // only WebSocketTransport
|
|
154
154
|
const client = new hl.EventClient({ transport });
|
|
@@ -225,22 +225,19 @@ const transport = new hl.WebSocketTransport();
|
|
|
225
225
|
const client = new hl.EventClient({ transport });
|
|
226
226
|
|
|
227
227
|
// L2 Book updates
|
|
228
|
-
|
|
228
|
+
await client.l2Book({ coin: "BTC" }, (data) => {
|
|
229
229
|
console.log(data);
|
|
230
230
|
});
|
|
231
|
-
await sub.unsubscribe();
|
|
232
231
|
|
|
233
232
|
// User fills
|
|
234
|
-
|
|
233
|
+
await client.userFills({ user: "0x..." }, (data) => {
|
|
235
234
|
console.log(data);
|
|
236
235
|
});
|
|
237
|
-
await sub.unsubscribe();
|
|
238
236
|
|
|
239
237
|
// Explorer block updates
|
|
240
|
-
|
|
238
|
+
await client.explorerBlock((data) => {
|
|
241
239
|
console.log(data);
|
|
242
240
|
});
|
|
243
|
-
await sub.unsubscribe();
|
|
244
241
|
```
|
|
245
242
|
|
|
246
243
|
## API Reference
|
|
@@ -270,6 +267,7 @@ class PublicClient {
|
|
|
270
267
|
l2Book(args: L2BookParameters): Promise<Book>;
|
|
271
268
|
meta(): Promise<PerpsMeta>;
|
|
272
269
|
metaAndAssetCtxs(): Promise<PerpsMetaAndAssetCtxs>;
|
|
270
|
+
perpDeployAuctionStatus(): Promise<DeployAuctionStatus>;
|
|
273
271
|
perpDexs(): Promise<(PerpDex | null)[]>;
|
|
274
272
|
perpsAtOpenInterestCap(): Promise<string[]>;
|
|
275
273
|
predictedFundings(): Promise<PredictedFunding[]>;
|
|
@@ -471,7 +469,6 @@ class HttpTransport {
|
|
|
471
469
|
constructor(options?: {
|
|
472
470
|
isTestnet?: boolean; // Whether to use testnet url (default: false)
|
|
473
471
|
timeout?: number; // Request timeout in ms (default: 10_000)
|
|
474
|
-
server?: "api" | "api2" | "api-ui"; // Server URL (default: "api" = "https://api.hyperliquid.xyz")
|
|
475
472
|
fetchOptions?: RequestInit; // A custom fetch options
|
|
476
473
|
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>; // A callback before request is sent
|
|
477
474
|
onResponse?: (response: Response) => MaybePromise<Response | void | null | undefined>; // A callback after response is received
|
|
@@ -492,7 +489,8 @@ class WebSocketTransport {
|
|
|
492
489
|
url?: string | URL; // WebSocket URL (default: "wss://api.hyperliquid.xyz/ws")
|
|
493
490
|
timeout?: number; // Request timeout in ms (default: 10_000)
|
|
494
491
|
keepAlive?: { // Keep-alive configuration
|
|
495
|
-
interval?: number; // Ping interval in ms (default:
|
|
492
|
+
interval?: number; // Ping interval in ms (default: 30_000)
|
|
493
|
+
timeout?: number; // Pong timeout in ms (default: same as `timeout` for requests)
|
|
496
494
|
};
|
|
497
495
|
reconnect?: { // Reconnection policy configuration for closed connections
|
|
498
496
|
maxRetries?: number; // Maximum number of reconnection attempts (default: 3)
|
|
@@ -518,21 +516,15 @@ class WebSocketTransport {
|
|
|
518
516
|
|
|
519
517
|
## Additional Import Points
|
|
520
518
|
|
|
521
|
-
The SDK exports additional import points to access internal functions.
|
|
522
|
-
|
|
523
519
|
### `/types`
|
|
524
520
|
|
|
525
521
|
The import point gives access to all Hyperliquid-related types, including the base types on which class methods are
|
|
526
522
|
based.
|
|
527
523
|
|
|
528
|
-
Useful if you want to get all Hyperliquid types.
|
|
529
|
-
|
|
530
524
|
### `/signing`
|
|
531
525
|
|
|
532
526
|
The import point gives access to functions that generate signatures for Hyperliquid transactions.
|
|
533
527
|
|
|
534
|
-
Useful if you want to sign a Hyperliquid transaction yourself.
|
|
535
|
-
|
|
536
528
|
### Examples
|
|
537
529
|
|
|
538
530
|
#### Cancel an order without a client
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface PromiseConstructor {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Promise that can be resolved or rejected using provided functions.
|
|
5
|
+
* @returns An object containing `promise` promise object, `resolve` and `reject` functions.
|
|
6
|
+
*/
|
|
7
|
+
withResolvers<T>(): {
|
|
8
|
+
promise: Promise<T>;
|
|
9
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
10
|
+
reject: (reason?: any) => void;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
interface Error {
|
|
16
|
+
cause?: unknown;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,kBAAkB;QAC1B;;;WAGG;QACH,aAAa,CAAC,CAAC,KAAK;YAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;YAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;YAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;SAAE,CAAC;KAC3H;CACF;AAaD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-promise-with-resolvers/blob/3a78801e073e99217dbeb2c43ba7212f3bdc8b83/polyfills.js#L1C1-L9C2
|
|
2
|
+
if (Promise.withResolvers === undefined) {
|
|
3
|
+
Promise.withResolvers = () => {
|
|
4
|
+
const out = {};
|
|
5
|
+
out.promise = new Promise((resolve_, reject_) => {
|
|
6
|
+
out.resolve = resolve_;
|
|
7
|
+
out.reject = reject_;
|
|
8
|
+
});
|
|
9
|
+
return out;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/esm/mod.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import "./_dnt.polyfills.js";
|
|
1
2
|
export * from "./src/base.js";
|
|
3
|
+
export * from "./src/transports/base.js";
|
|
2
4
|
export type { AbstractEthersSigner, AbstractEthersV5Signer, AbstractExtendedViemWalletClient, AbstractViemWalletClient, AbstractWindowEthereum, } from "./src/signing.js";
|
|
3
5
|
export * from "./src/clients/event.js";
|
|
4
6
|
export * from "./src/clients/public.js";
|
|
@@ -10,6 +12,7 @@ export type * from "./src/types/explorer/responses.js";
|
|
|
10
12
|
export type * from "./src/types/info/accounts.js";
|
|
11
13
|
export type * from "./src/types/info/assets.js";
|
|
12
14
|
export type * from "./src/types/info/delegations.js";
|
|
15
|
+
export type * from "./src/types/info/markets.js";
|
|
13
16
|
export type * from "./src/types/info/orders.js";
|
|
14
17
|
export type * from "./src/types/info/vaults.js";
|
|
15
18
|
export type * from "./src/types/subscriptions/responses.js";
|
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,qBAAqB,CAAC;AAE7B,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AAGzC,YAAY,EACR,oBAAoB,EACpB,sBAAsB,EACtB,gCAAgC,EAChC,wBAAwB,EACxB,sBAAsB,GACzB,MAAM,kBAAkB,CAAC;AAG1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAGlE,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,iCAAiC,CAAC;AACrD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,wCAAwC,CAAC"}
|
package/esm/mod.js
CHANGED
package/esm/src/base.d.ts
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
/** Hexadecimal string starting with `0x`. */
|
|
2
1
|
export type Hex = `0x${string}`;
|
|
3
2
|
export type MaybePromise<T> = T | Promise<T>;
|
|
4
|
-
/**
|
|
5
|
-
* Interface representing a REST transport.
|
|
6
|
-
* Handles communication with Hyperliquid API endpoints.
|
|
7
|
-
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint | Info endpoint}
|
|
8
|
-
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint | Exchange endpoint}
|
|
9
|
-
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/post-requests | Websocket post requests}
|
|
10
|
-
*/
|
|
11
|
-
export interface IRequestTransport extends Partial<AsyncDisposable> {
|
|
12
|
-
/**
|
|
13
|
-
* Sends a request to the Hyperliquid API.
|
|
14
|
-
* @param endpoint - The API endpoint to send the request to.
|
|
15
|
-
* @param payload - The payload to send with the request.
|
|
16
|
-
* @param signal - An ptional abort signal.
|
|
17
|
-
* @returns A promise that resolves with parsed JSON response body.
|
|
18
|
-
*/
|
|
19
|
-
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Interface representing an event subscription transport.
|
|
23
|
-
* Handles WebSocket subscriptions for real-time updates.
|
|
24
|
-
* @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions | Websocket subscriptions}
|
|
25
|
-
*/
|
|
26
|
-
export interface ISubscriptionTransport extends Partial<AsyncDisposable> {
|
|
27
|
-
/**
|
|
28
|
-
* Subscribes to a Hyperliquid event channel.
|
|
29
|
-
* @param channel - The event channel to listen to.
|
|
30
|
-
* @param payload - The payload to send with the subscription request.
|
|
31
|
-
* @param listener - The function to call when the event is dispatched.
|
|
32
|
-
* @param signal - An optional abort signal for canceling the subscription request.
|
|
33
|
-
* @returns A promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
34
|
-
*/
|
|
35
|
-
subscribe(channel: string, payload: unknown, listener: (data: CustomEvent) => void, signal?: AbortSignal): Promise<Subscription>;
|
|
36
|
-
}
|
|
37
|
-
/** Controls event subscription lifecycle. */
|
|
38
|
-
export interface Subscription {
|
|
39
|
-
/**
|
|
40
|
-
* Unsubscribes from the event and sends an unsubscribe request to the server.
|
|
41
|
-
* @param signal - An optional abort signal for canceling the unsubscribe request.
|
|
42
|
-
*/
|
|
43
|
-
unsubscribe(signal?: AbortSignal): Promise<void>;
|
|
44
|
-
}
|
|
45
|
-
/** Base class for all Hyperliquid SDK errors. */
|
|
3
|
+
/** Base error class for all SDK errors. */
|
|
46
4
|
export declare class HyperliquidError extends Error {
|
|
47
5
|
constructor(message?: string);
|
|
48
6
|
}
|
|
49
|
-
/** Base class for all transport-related errors. */
|
|
50
|
-
export declare class TransportError extends HyperliquidError {
|
|
51
|
-
constructor(message?: string);
|
|
52
|
-
}
|
|
53
7
|
//# sourceMappingURL=base.d.ts.map
|
package/esm/src/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM;CAI/B"}
|
package/esm/src/base.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
/** Base class for all
|
|
1
|
+
/** Base error class for all SDK errors. */
|
|
2
2
|
export class HyperliquidError extends Error {
|
|
3
3
|
constructor(message) {
|
|
4
4
|
super(message);
|
|
5
5
|
this.name = "HyperliquidError";
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
/** Base class for all transport-related errors. */
|
|
9
|
-
export class TransportError extends HyperliquidError {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = "TransportError";
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ISubscriptionTransport, Subscription } from "../base.js";
|
|
1
|
+
import type { ISubscriptionTransport, Subscription } from "../transports/base.js";
|
|
2
2
|
import type { WsActiveAssetCtxRequest, WsActiveAssetDataRequest, WsAllMidsRequest, WsBboRequest, WsCandleRequest, WsL2BookRequest, WsNotificationRequest, WsOrderUpdatesRequest, WsTradesRequest, WsUserEventsRequest, WsUserFillsRequest, WsUserFundingsRequest, WsUserNonFundingLedgerUpdatesRequest, WsUserTwapHistoryRequest, WsUserTwapSliceFillsRequest, WsWebData2Request } from "../types/subscriptions/requests.js";
|
|
3
3
|
import type { WsActiveAssetCtx, WsActiveAssetData, WsActiveSpotAssetCtx, WsAllMids, WsBbo, WsBlockDetails, WsNotification, WsTrade, WsUserEvent, WsUserFills, WsUserFundings, WsUserNonFundingLedgerUpdates, WsUserTwapHistory, WsUserTwapSliceFills, WsWebData2 } from "../types/subscriptions/responses.js";
|
|
4
4
|
import type { Candle } from "../types/info/assets.js";
|
|
@@ -45,8 +45,7 @@ export type EventWebData2Parameters = Omit<WsWebData2Request, "type">;
|
|
|
45
45
|
* Event client for subscribing to various Hyperliquid events.
|
|
46
46
|
* @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
|
|
47
47
|
*/
|
|
48
|
-
export declare class EventClient<T extends ISubscriptionTransport = ISubscriptionTransport> implements AsyncDisposable {
|
|
49
|
-
/** The transport used to connect to the Hyperliquid API. */
|
|
48
|
+
export declare class EventClient<T extends ISubscriptionTransport = ISubscriptionTransport> implements EventClientParameters, AsyncDisposable {
|
|
50
49
|
transport: T;
|
|
51
50
|
/**
|
|
52
51
|
* Initialises a new instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/src/clients/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/src/clients/event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,KAAK,EACR,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,YAAY,EACZ,eAAe,EAGf,eAAe,EACf,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,2BAA2B,EAC3B,iBAAiB,EACpB,MAAM,oC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CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,EACxC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,2BAA2B,CACvB,IAAI,EAAE,0CAA0C,EAChD,QAAQ,EAAE,CAAC,IAAI,EAAE,6BAA6B,KAAK,IAAI,EACvD,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,CACX,IAAI,EAAE,oBAAoB,EAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,EAC3C,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CACd,IAAI,EAAE,uBAAuB,EAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,EAC9C,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAYxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CACJ,IAAI,EAAE,uBAAuB,EAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,EACpC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC;IAYlB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/C"}
|
package/esm/src/clients/event.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @typeParam T The type of transport used to connect to the Hyperliquid Websocket API.
|
|
4
4
|
*/
|
|
5
5
|
export class EventClient {
|
|
6
|
+
transport;
|
|
6
7
|
/**
|
|
7
8
|
* Initialises a new instance.
|
|
8
9
|
* @param args - The arguments for initialisation.
|
|
@@ -16,13 +17,6 @@ export class EventClient {
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
constructor(args) {
|
|
19
|
-
/** The transport used to connect to the Hyperliquid API. */
|
|
20
|
-
Object.defineProperty(this, "transport", {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
configurable: true,
|
|
23
|
-
writable: true,
|
|
24
|
-
value: void 0
|
|
25
|
-
});
|
|
26
20
|
this.transport = args.transport;
|
|
27
21
|
}
|
|
28
22
|
/**
|
|
@@ -51,9 +45,9 @@ export class EventClient {
|
|
|
51
45
|
type: "activeAssetCtx",
|
|
52
46
|
coin: args.coin,
|
|
53
47
|
};
|
|
54
|
-
return this.transport.subscribe(channel, payload, (
|
|
55
|
-
if (
|
|
56
|
-
listener(
|
|
48
|
+
return this.transport.subscribe(channel, payload, (e) => {
|
|
49
|
+
if (e.detail.coin === args.coin) {
|
|
50
|
+
listener(e.detail);
|
|
57
51
|
}
|
|
58
52
|
}, signal);
|
|
59
53
|
}
|
|
@@ -83,9 +77,9 @@ export class EventClient {
|
|
|
83
77
|
coin: args.coin,
|
|
84
78
|
user: args.user,
|
|
85
79
|
};
|
|
86
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
87
|
-
if (
|
|
88
|
-
listener(
|
|
80
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
81
|
+
if (e.detail.coin === args.coin && e.detail.user === args.user.toLowerCase()) {
|
|
82
|
+
listener(e.detail);
|
|
89
83
|
}
|
|
90
84
|
}, signal);
|
|
91
85
|
}
|
|
@@ -101,8 +95,8 @@ export class EventClient {
|
|
|
101
95
|
type: "allMids",
|
|
102
96
|
dex: args.dex,
|
|
103
97
|
};
|
|
104
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
105
|
-
listener(
|
|
98
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
99
|
+
listener(e.detail);
|
|
106
100
|
}, signal);
|
|
107
101
|
}
|
|
108
102
|
/**
|
|
@@ -130,9 +124,9 @@ export class EventClient {
|
|
|
130
124
|
type: "bbo",
|
|
131
125
|
coin: args.coin,
|
|
132
126
|
};
|
|
133
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
134
|
-
if (
|
|
135
|
-
listener(
|
|
127
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
128
|
+
if (e.detail.coin === args.coin) {
|
|
129
|
+
listener(e.detail);
|
|
136
130
|
}
|
|
137
131
|
}, signal);
|
|
138
132
|
}
|
|
@@ -162,9 +156,9 @@ export class EventClient {
|
|
|
162
156
|
coin: args.coin,
|
|
163
157
|
interval: args.interval,
|
|
164
158
|
};
|
|
165
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
166
|
-
if (
|
|
167
|
-
listener(
|
|
159
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
160
|
+
if (e.detail.s === args.coin && e.detail.i === args.interval) {
|
|
161
|
+
listener(e.detail);
|
|
168
162
|
}
|
|
169
163
|
}, signal);
|
|
170
164
|
}
|
|
@@ -192,9 +186,8 @@ export class EventClient {
|
|
|
192
186
|
const payload = {
|
|
193
187
|
type: "explorerBlock",
|
|
194
188
|
};
|
|
195
|
-
return this.transport.subscribe("_explorerBlock",
|
|
196
|
-
|
|
197
|
-
listener(event.detail);
|
|
189
|
+
return this.transport.subscribe("_explorerBlock", payload, (e) => {
|
|
190
|
+
listener(e.detail);
|
|
198
191
|
}, signal);
|
|
199
192
|
}
|
|
200
193
|
/**
|
|
@@ -221,9 +214,8 @@ export class EventClient {
|
|
|
221
214
|
const payload = {
|
|
222
215
|
type: "explorerTxs",
|
|
223
216
|
};
|
|
224
|
-
return this.transport.subscribe("_explorerTxs",
|
|
225
|
-
|
|
226
|
-
listener(event.detail);
|
|
217
|
+
return this.transport.subscribe("_explorerTxs", payload, (e) => {
|
|
218
|
+
listener(e.detail);
|
|
227
219
|
}, signal);
|
|
228
220
|
}
|
|
229
221
|
/**
|
|
@@ -253,9 +245,9 @@ export class EventClient {
|
|
|
253
245
|
nSigFigs: args.nSigFigs ?? null,
|
|
254
246
|
mantissa: args.mantissa ?? null,
|
|
255
247
|
};
|
|
256
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
257
|
-
if (
|
|
258
|
-
listener(
|
|
248
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
249
|
+
if (e.detail.coin === args.coin) {
|
|
250
|
+
listener(e.detail);
|
|
259
251
|
}
|
|
260
252
|
}, signal);
|
|
261
253
|
}
|
|
@@ -284,8 +276,8 @@ export class EventClient {
|
|
|
284
276
|
type: "notification",
|
|
285
277
|
user: args.user,
|
|
286
278
|
};
|
|
287
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
288
|
-
listener(
|
|
279
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
280
|
+
listener(e.detail);
|
|
289
281
|
}, signal);
|
|
290
282
|
}
|
|
291
283
|
/**
|
|
@@ -313,8 +305,8 @@ export class EventClient {
|
|
|
313
305
|
type: "orderUpdates",
|
|
314
306
|
user: args.user,
|
|
315
307
|
};
|
|
316
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
317
|
-
listener(
|
|
308
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
309
|
+
listener(e.detail);
|
|
318
310
|
}, signal);
|
|
319
311
|
}
|
|
320
312
|
/**
|
|
@@ -342,9 +334,9 @@ export class EventClient {
|
|
|
342
334
|
type: "trades",
|
|
343
335
|
coin: args.coin,
|
|
344
336
|
};
|
|
345
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
346
|
-
if (
|
|
347
|
-
listener(
|
|
337
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
338
|
+
if (e.detail[0]?.coin === args.coin) {
|
|
339
|
+
listener(e.detail);
|
|
348
340
|
}
|
|
349
341
|
}, signal);
|
|
350
342
|
}
|
|
@@ -375,8 +367,8 @@ export class EventClient {
|
|
|
375
367
|
type: "userEvents",
|
|
376
368
|
user: args.user,
|
|
377
369
|
};
|
|
378
|
-
return this.transport.subscribe("user", payload, (
|
|
379
|
-
listener(
|
|
370
|
+
return this.transport.subscribe("user", payload, (e) => {
|
|
371
|
+
listener(e.detail);
|
|
380
372
|
}, signal);
|
|
381
373
|
}
|
|
382
374
|
/**
|
|
@@ -405,9 +397,9 @@ export class EventClient {
|
|
|
405
397
|
user: args.user,
|
|
406
398
|
aggregateByTime: args.aggregateByTime ?? false,
|
|
407
399
|
};
|
|
408
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
409
|
-
if (
|
|
410
|
-
listener(
|
|
400
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
401
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
402
|
+
listener(e.detail);
|
|
411
403
|
}
|
|
412
404
|
}, signal);
|
|
413
405
|
}
|
|
@@ -436,9 +428,9 @@ export class EventClient {
|
|
|
436
428
|
type: "userFundings",
|
|
437
429
|
user: args.user,
|
|
438
430
|
};
|
|
439
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
440
|
-
if (
|
|
441
|
-
listener(
|
|
431
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
432
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
433
|
+
listener(e.detail);
|
|
442
434
|
}
|
|
443
435
|
}, signal);
|
|
444
436
|
}
|
|
@@ -467,9 +459,9 @@ export class EventClient {
|
|
|
467
459
|
type: "userNonFundingLedgerUpdates",
|
|
468
460
|
user: args.user,
|
|
469
461
|
};
|
|
470
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
471
|
-
if (
|
|
472
|
-
listener(
|
|
462
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
463
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
464
|
+
listener(e.detail);
|
|
473
465
|
}
|
|
474
466
|
}, signal);
|
|
475
467
|
}
|
|
@@ -498,9 +490,9 @@ export class EventClient {
|
|
|
498
490
|
type: "userTwapHistory",
|
|
499
491
|
user: args.user,
|
|
500
492
|
};
|
|
501
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
502
|
-
if (
|
|
503
|
-
listener(
|
|
493
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
494
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
495
|
+
listener(e.detail);
|
|
504
496
|
}
|
|
505
497
|
}, signal);
|
|
506
498
|
}
|
|
@@ -529,9 +521,9 @@ export class EventClient {
|
|
|
529
521
|
type: "userTwapSliceFills",
|
|
530
522
|
user: args.user,
|
|
531
523
|
};
|
|
532
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
533
|
-
if (
|
|
534
|
-
listener(
|
|
524
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
525
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
526
|
+
listener(e.detail);
|
|
535
527
|
}
|
|
536
528
|
}, signal);
|
|
537
529
|
}
|
|
@@ -560,9 +552,9 @@ export class EventClient {
|
|
|
560
552
|
type: "webData2",
|
|
561
553
|
user: args.user,
|
|
562
554
|
};
|
|
563
|
-
return this.transport.subscribe(payload.type, payload, (
|
|
564
|
-
if (
|
|
565
|
-
listener(
|
|
555
|
+
return this.transport.subscribe(payload.type, payload, (e) => {
|
|
556
|
+
if (e.detail.user === args.user.toLowerCase()) {
|
|
557
|
+
listener(e.detail);
|
|
566
558
|
}
|
|
567
559
|
}, signal);
|
|
568
560
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { IRequestTransport } from "../base.js";
|
|
1
|
+
import type { IRequestTransport } from "../transports/base.js";
|
|
2
2
|
import type { BlockDetailsRequest, TxDetailsRequest, UserDetailsRequest } from "../types/explorer/requests.js";
|
|
3
3
|
import type { BlockDetailsResponse, TxDetailsResponse, UserDetailsResponse } from "../types/explorer/responses.js";
|
|
4
4
|
import type { ExtraAgent, LegalCheck, MultiSigSigners, PerpsClearinghouseState, PortfolioPeriods, PreTransferCheck, Referral, SpotClearinghouseState, SubAccount, UserFees, UserFundingUpdate, UserNonFundingLedgerUpdate, UserRateLimit, UserRole } from "../types/info/accounts.js";
|
|
5
|
-
import type { AllMids, Candle, FundingHistory, PerpDex, PerpsMeta, PerpsMetaAndAssetCtxs, PredictedFunding,
|
|
5
|
+
import type { AllMids, Candle, FundingHistory, PerpDex, PerpsMeta, PerpsMetaAndAssetCtxs, PredictedFunding, SpotMeta, SpotMetaAndAssetCtxs, TokenDetails } from "../types/info/assets.js";
|
|
6
6
|
import type { Delegation, DelegatorReward, DelegatorSummary, DelegatorUpdate, ValidatorSummary } from "../types/info/delegations.js";
|
|
7
|
+
import type { DeployAuctionStatus, SpotDeployState } from "../types/info/markets.js";
|
|
7
8
|
import type { Book, Fill, FrontendOrder, Order, OrderLookup, OrderStatus, TwapHistory, TwapSliceFill } from "../types/info/orders.js";
|
|
8
|
-
import type { AllMidsRequest, CandleSnapshotRequest, ClearinghouseStateRequest, DelegationsRequest, DelegatorHistoryRequest, DelegatorRewardsRequest, DelegatorSummaryRequest, ExtraAgentsRequest, FrontendOpenOrdersRequest, FundingHistoryRequest, HistoricalOrdersRequest, IsVipRequest, L2BookRequest, LegalCheckRequest, MaxBuilderFeeRequest, MetaRequest, OpenOrdersRequest, OrderStatusRequest, PerpDexsRequest, PortfolioRequest, PreTransferCheckRequest, ReferralRequest, SpotClearinghouseStateRequest, SpotDeployStateRequest, SubAccountsRequest, TokenDetailsRequest, TwapHistoryRequest, UserFeesRequest, UserFillsByTimeRequest, UserFillsRequest, UserFundingRequest, UserNonFundingLedgerUpdatesRequest, UserRateLimitRequest, UserRoleRequest, UserToMultiSigSignersRequest, UserTwapSliceFillsByTimeRequest, UserTwapSliceFillsRequest, UserVaultEquitiesRequest, VaultDetailsRequest } from "../types/info/requests.js";
|
|
9
|
+
import type { AllMidsRequest, CandleSnapshotRequest, ClearinghouseStateRequest, DelegationsRequest, DelegatorHistoryRequest, DelegatorRewardsRequest, DelegatorSummaryRequest, ExtraAgentsRequest, FrontendOpenOrdersRequest, FundingHistoryRequest, HistoricalOrdersRequest, IsVipRequest, L2BookRequest, LegalCheckRequest, MaxBuilderFeeRequest, MetaRequest, OpenOrdersRequest, OrderStatusRequest, PerpDeployAuctionStatusRequest, PerpDexsRequest, PortfolioRequest, PreTransferCheckRequest, ReferralRequest, SpotClearinghouseStateRequest, SpotDeployStateRequest, SubAccountsRequest, TokenDetailsRequest, TwapHistoryRequest, UserFeesRequest, UserFillsByTimeRequest, UserFillsRequest, UserFundingRequest, UserNonFundingLedgerUpdatesRequest, UserRateLimitRequest, UserRoleRequest, UserToMultiSigSignersRequest, UserTwapSliceFillsByTimeRequest, UserTwapSliceFillsRequest, UserVaultEquitiesRequest, VaultDetailsRequest } from "../types/info/requests.js";
|
|
9
10
|
import type { VaultDetails, VaultEquity, VaultSummary } from "../types/info/vaults.js";
|
|
10
11
|
/** Parameters for the {@linkcode PublicClient} constructor. */
|
|
11
12
|
export interface PublicClientParameters<T extends IRequestTransport = IRequestTransport> {
|
|
@@ -48,6 +49,8 @@ export type MetaParameters = Omit<MetaRequest, "type">;
|
|
|
48
49
|
export type OpenOrdersParameters = Omit<OpenOrdersRequest, "type">;
|
|
49
50
|
/** Parameters for the {@linkcode PublicClient.orderStatus} method. */
|
|
50
51
|
export type OrderStatusParameters = Omit<OrderStatusRequest, "type">;
|
|
52
|
+
/** Parameters for the {@linkcode PublicClient.perpDeployAuctionStatus} method. */
|
|
53
|
+
export type PerpDeployAuctionStatusParameters = Omit<PerpDeployAuctionStatusRequest, "type">;
|
|
51
54
|
/** Parameters for the {@linkcode PublicClient.perpDexs} method. */
|
|
52
55
|
export type PerpDexsParameters = Omit<PerpDexsRequest, "type">;
|
|
53
56
|
/** Parameters for the {@linkcode PublicClient.portfolio} method. */
|
|
@@ -100,8 +103,7 @@ export type UserDetailsParameters = Omit<UserDetailsRequest, "type">;
|
|
|
100
103
|
* Public client for interacting with the Hyperliquid API.
|
|
101
104
|
* @typeParam T The type of transport used to connect to the Hyperliquid API.
|
|
102
105
|
*/
|
|
103
|
-
export declare class PublicClient<T extends IRequestTransport = IRequestTransport> implements AsyncDisposable {
|
|
104
|
-
/** The transport used to connect to the Hyperliquid API. */
|
|
106
|
+
export declare class PublicClient<T extends IRequestTransport = IRequestTransport> implements PublicClientParameters, AsyncDisposable {
|
|
105
107
|
transport: T;
|
|
106
108
|
/**
|
|
107
109
|
* Initialises a new instance.
|
|
@@ -482,6 +484,23 @@ export declare class PublicClient<T extends IRequestTransport = IRequestTranspor
|
|
|
482
484
|
* ```
|
|
483
485
|
*/
|
|
484
486
|
orderStatus(args: OrderStatusParameters, signal?: AbortSignal): Promise<OrderLookup>;
|
|
487
|
+
/**
|
|
488
|
+
* Request for the status of the perpetual deploy auction.
|
|
489
|
+
* @param signal - An optional abort signal.
|
|
490
|
+
* @returns Status of the perpetual deploy auction.
|
|
491
|
+
*
|
|
492
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-information-about-the-perp-deploy-auction
|
|
493
|
+
* @example
|
|
494
|
+
* ```ts
|
|
495
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
496
|
+
*
|
|
497
|
+
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
498
|
+
* const client = new hl.PublicClient({ transport });
|
|
499
|
+
*
|
|
500
|
+
* const auctionStatus = await client.perpDeployAuctionStatus();
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
perpDeployAuctionStatus(signal?: AbortSignal): Promise<DeployAuctionStatus>;
|
|
485
504
|
/**
|
|
486
505
|
* Request all perpetual dexs.
|
|
487
506
|
* @param signal - An optional abort signal.
|