@nktkas/hyperliquid 0.28.0 → 0.29.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/esm/src/api/exchange/_methods/_base/execute.d.ts +7 -4
- package/esm/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
- package/esm/src/api/exchange/_methods/_base/execute.js +28 -20
- package/esm/src/api/exchange/_methods/_base/execute.js.map +1 -1
- package/esm/src/api/exchange/client.d.ts +6 -6
- package/esm/src/api/exchange/client.d.ts.map +1 -1
- package/esm/src/api/exchange/client.js +4 -4
- package/esm/src/api/subscription/_methods/allDexsAssetCtxs.d.ts +90 -0
- package/esm/src/api/subscription/_methods/allDexsAssetCtxs.d.ts.map +1 -0
- package/esm/src/api/subscription/_methods/allDexsAssetCtxs.js +78 -0
- package/esm/src/api/subscription/_methods/allDexsAssetCtxs.js.map +1 -0
- package/esm/src/api/subscription/_methods/allDexsClearinghouseState.d.ts +325 -0
- package/esm/src/api/subscription/_methods/allDexsClearinghouseState.d.ts.map +1 -0
- package/esm/src/api/subscription/_methods/allDexsClearinghouseState.js +65 -0
- package/esm/src/api/subscription/_methods/allDexsClearinghouseState.js.map +1 -0
- package/esm/src/api/subscription/client.d.ts +8 -0
- package/esm/src/api/subscription/client.d.ts.map +1 -1
- package/esm/src/api/subscription/client.js +10 -0
- package/esm/src/api/subscription/client.js.map +1 -1
- package/esm/src/api/subscription/mod.d.ts +2 -0
- package/esm/src/api/subscription/mod.d.ts.map +1 -1
- package/esm/src/api/subscription/mod.js +2 -0
- package/esm/src/api/subscription/mod.js.map +1 -1
- package/package.json +1 -1
- package/script/src/api/exchange/_methods/_base/execute.d.ts +7 -4
- package/script/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
- package/script/src/api/exchange/_methods/_base/execute.js +28 -20
- package/script/src/api/exchange/_methods/_base/execute.js.map +1 -1
- package/script/src/api/exchange/client.d.ts +6 -6
- package/script/src/api/exchange/client.d.ts.map +1 -1
- package/script/src/api/exchange/client.js +4 -4
- package/script/src/api/subscription/_methods/allDexsAssetCtxs.d.ts +90 -0
- package/script/src/api/subscription/_methods/allDexsAssetCtxs.d.ts.map +1 -0
- package/script/src/api/subscription/_methods/allDexsAssetCtxs.js +115 -0
- package/script/src/api/subscription/_methods/allDexsAssetCtxs.js.map +1 -0
- package/script/src/api/subscription/_methods/allDexsClearinghouseState.d.ts +325 -0
- package/script/src/api/subscription/_methods/allDexsClearinghouseState.d.ts.map +1 -0
- package/script/src/api/subscription/_methods/allDexsClearinghouseState.js +102 -0
- package/script/src/api/subscription/_methods/allDexsClearinghouseState.js.map +1 -0
- package/script/src/api/subscription/client.d.ts +8 -0
- package/script/src/api/subscription/client.d.ts.map +1 -1
- package/script/src/api/subscription/client.js +10 -0
- package/script/src/api/subscription/client.js.map +1 -1
- package/script/src/api/subscription/mod.d.ts +2 -0
- package/script/src/api/subscription/mod.d.ts.map +1 -1
- package/script/src/api/subscription/mod.js +2 -0
- package/script/src/api/subscription/mod.js.map +1 -1
- package/src/src/api/exchange/_methods/_base/execute.ts +36 -23
- package/src/src/api/exchange/client.ts +6 -6
- package/src/src/api/subscription/_methods/allDexsAssetCtxs.ts +140 -0
- package/src/src/api/subscription/_methods/allDexsClearinghouseState.ts +105 -0
- package/src/src/api/subscription/client.ts +26 -0
- package/src/src/api/subscription/mod.ts +2 -0
|
@@ -24,9 +24,15 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
24
24
|
// deno-lint-ignore ban-types
|
|
25
25
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
26
26
|
|
|
27
|
+
/** Options for any execute functions. */
|
|
28
|
+
interface BaseOptions {
|
|
29
|
+
/** [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel a request. */
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
/** Extract request options from a request type (excludes action, nonce, signature). */
|
|
28
34
|
export type ExtractRequestOptions<T extends { action: Record<string, unknown> }> = Prettify<
|
|
29
|
-
&
|
|
35
|
+
& BaseOptions
|
|
30
36
|
& Omit<T, "action" | "nonce" | "signature">
|
|
31
37
|
>;
|
|
32
38
|
|
|
@@ -75,7 +81,7 @@ export interface ExchangeMultiSigConfig<
|
|
|
75
81
|
T extends HttpTransport | WebSocketTransport = HttpTransport | WebSocketTransport,
|
|
76
82
|
> extends BaseConfig<T> {
|
|
77
83
|
/** Array of wallets for multi-sig. First wallet is the leader. */
|
|
78
|
-
|
|
84
|
+
signers: readonly [AbstractWallet, ...AbstractWallet[]];
|
|
79
85
|
/** The multi-signature account address. */
|
|
80
86
|
multiSigUser: `0x${string}`;
|
|
81
87
|
}
|
|
@@ -124,9 +130,8 @@ export async function executeL1Action<T>(
|
|
|
124
130
|
const signal = options?.signal;
|
|
125
131
|
|
|
126
132
|
// Sign action (multi-sig or single wallet)
|
|
127
|
-
const [finalAction, signature] =
|
|
128
|
-
?
|
|
129
|
-
: [
|
|
133
|
+
const [finalAction, signature] = "wallet" in config
|
|
134
|
+
? [
|
|
130
135
|
action,
|
|
131
136
|
await signL1Action({
|
|
132
137
|
wallet: leader,
|
|
@@ -136,7 +141,8 @@ export async function executeL1Action<T>(
|
|
|
136
141
|
vaultAddress,
|
|
137
142
|
expiresAfter,
|
|
138
143
|
}),
|
|
139
|
-
]
|
|
144
|
+
]
|
|
145
|
+
: await signMultiSigL1(config, action, walletAddress, nonce, vaultAddress, expiresAfter);
|
|
140
146
|
|
|
141
147
|
// Send request and validate response
|
|
142
148
|
const response = await transport.request("exchange", {
|
|
@@ -200,9 +206,9 @@ export async function executeUserSignedAction<T>(
|
|
|
200
206
|
};
|
|
201
207
|
|
|
202
208
|
// Sign action (multi-sig or single wallet)
|
|
203
|
-
const [finalAction, signature] =
|
|
204
|
-
? await
|
|
205
|
-
:
|
|
209
|
+
const [finalAction, signature] = "wallet" in config
|
|
210
|
+
? [fullAction, await signUserSignedAction({ wallet: leader, action: fullAction, types })]
|
|
211
|
+
: await signMultiSigUserSigned(config, fullAction, types, walletAddress, nonce);
|
|
206
212
|
|
|
207
213
|
// Send request and validate response
|
|
208
214
|
const response = await transport.request("exchange", {
|
|
@@ -216,7 +222,7 @@ export async function executeUserSignedAction<T>(
|
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
// =============================================================
|
|
219
|
-
// Multi-sig signing
|
|
225
|
+
// Multi-sig signing
|
|
220
226
|
// =============================================================
|
|
221
227
|
|
|
222
228
|
/** Remove leading zeros from signature components (required by Hyperliquid). */
|
|
@@ -237,7 +243,7 @@ async function signMultiSigL1(
|
|
|
237
243
|
vaultAddress?: `0x${string}`,
|
|
238
244
|
expiresAfter?: number,
|
|
239
245
|
): Promise<[Record<string, unknown>, Signature]> {
|
|
240
|
-
const { transport: { isTestnet },
|
|
246
|
+
const { transport: { isTestnet }, signers, multiSigUser } = config;
|
|
241
247
|
const multiSigUser_ = v.parse(Address, multiSigUser);
|
|
242
248
|
const outerSigner_ = v.parse(Address, outerSigner);
|
|
243
249
|
|
|
@@ -259,7 +265,11 @@ async function signMultiSigL1(
|
|
|
259
265
|
type: "multiSig",
|
|
260
266
|
signatureChainId: await getSignatureChainId(config),
|
|
261
267
|
signatures,
|
|
262
|
-
payload: {
|
|
268
|
+
payload: {
|
|
269
|
+
multiSigUser: multiSigUser_,
|
|
270
|
+
outerSigner: outerSigner_,
|
|
271
|
+
action,
|
|
272
|
+
},
|
|
263
273
|
};
|
|
264
274
|
|
|
265
275
|
// Sign the wrapper with the leader
|
|
@@ -283,7 +293,7 @@ async function signMultiSigUserSigned(
|
|
|
283
293
|
outerSigner: `0x${string}`,
|
|
284
294
|
nonce: number,
|
|
285
295
|
): Promise<[Record<string, unknown>, Signature]> {
|
|
286
|
-
const {
|
|
296
|
+
const { signers, multiSigUser, transport: { isTestnet } } = config;
|
|
287
297
|
const multiSigUser_ = v.parse(Address, multiSigUser);
|
|
288
298
|
const outerSigner_ = v.parse(Address, outerSigner);
|
|
289
299
|
|
|
@@ -291,7 +301,11 @@ async function signMultiSigUserSigned(
|
|
|
291
301
|
const signatures = await Promise.all(signers.map(async (signer) => {
|
|
292
302
|
const signature = await signUserSignedAction({
|
|
293
303
|
wallet: signer,
|
|
294
|
-
action: {
|
|
304
|
+
action: {
|
|
305
|
+
payloadMultiSigUser: multiSigUser_,
|
|
306
|
+
outerSigner: outerSigner_,
|
|
307
|
+
...action,
|
|
308
|
+
},
|
|
295
309
|
types,
|
|
296
310
|
});
|
|
297
311
|
return trimSignature(signature);
|
|
@@ -302,7 +316,11 @@ async function signMultiSigUserSigned(
|
|
|
302
316
|
type: "multiSig",
|
|
303
317
|
signatureChainId: await getSignatureChainId(config),
|
|
304
318
|
signatures,
|
|
305
|
-
payload: {
|
|
319
|
+
payload: {
|
|
320
|
+
multiSigUser: multiSigUser_,
|
|
321
|
+
outerSigner: outerSigner_,
|
|
322
|
+
action,
|
|
323
|
+
},
|
|
306
324
|
};
|
|
307
325
|
|
|
308
326
|
// Sign the wrapper with the leader
|
|
@@ -317,17 +335,12 @@ async function signMultiSigUserSigned(
|
|
|
317
335
|
}
|
|
318
336
|
|
|
319
337
|
// =============================================================
|
|
320
|
-
// Helpers
|
|
338
|
+
// Helpers
|
|
321
339
|
// =============================================================
|
|
322
340
|
|
|
323
|
-
/**
|
|
324
|
-
function isMultiSig(config: ExchangeConfig): config is ExchangeMultiSigConfig {
|
|
325
|
-
return Array.isArray(config.wallet);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/** Get the leader wallet (first signer for multi-sig, or the single wallet). */
|
|
341
|
+
/** Get the leader wallet (first signer for the single wallet, or multi-sig). */
|
|
329
342
|
function getLeader(config: ExchangeConfig): AbstractWallet {
|
|
330
|
-
return
|
|
343
|
+
return "wallet" in config ? config.wallet : config.signers[0];
|
|
331
344
|
}
|
|
332
345
|
|
|
333
346
|
/** Resolve signature chain ID from config or wallet. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExchangeConfig } from "./_methods/_base/execute.js";
|
|
1
|
+
import type { ExchangeConfig, ExchangeSingleWalletConfig } from "./_methods/_base/execute.js";
|
|
2
2
|
|
|
3
3
|
// =============================================================
|
|
4
4
|
// Methods Imports
|
|
@@ -256,7 +256,7 @@ import {
|
|
|
256
256
|
/**
|
|
257
257
|
* A client for interacting with the Hyperliquid Exchange API.
|
|
258
258
|
*/
|
|
259
|
-
export class ExchangeClient<C extends ExchangeConfig =
|
|
259
|
+
export class ExchangeClient<C extends ExchangeConfig = ExchangeSingleWalletConfig> {
|
|
260
260
|
config_: C;
|
|
261
261
|
|
|
262
262
|
/**
|
|
@@ -290,15 +290,15 @@ export class ExchangeClient<C extends ExchangeConfig = ExchangeConfig> {
|
|
|
290
290
|
* import { privateKeyToAccount } from "npm:viem/accounts";
|
|
291
291
|
* import { ethers } from "npm:ethers";
|
|
292
292
|
*
|
|
293
|
-
* const
|
|
294
|
-
* const
|
|
295
|
-
* // ... and more
|
|
293
|
+
* const signer1 = privateKeyToAccount("0x...");
|
|
294
|
+
* const signer2 = new ethers.Wallet("0x...");
|
|
295
|
+
* // ... and more signers
|
|
296
296
|
*
|
|
297
297
|
* const transport = new hl.HttpTransport(); // or `WebSocketTransport`
|
|
298
298
|
*
|
|
299
299
|
* const client = new hl.ExchangeClient({
|
|
300
300
|
* transport,
|
|
301
|
-
*
|
|
301
|
+
* signers: [signer1, signer2],
|
|
302
302
|
* multiSigUser: "0x...",
|
|
303
303
|
* });
|
|
304
304
|
* ```
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
// ============================================================
|
|
4
|
+
// API Schemas
|
|
5
|
+
// ============================================================
|
|
6
|
+
|
|
7
|
+
import { Decimal, UnsignedDecimal } from "../../_schemas.js";
|
|
8
|
+
|
|
9
|
+
/** Subscription to asset context events for all DEXs. */
|
|
10
|
+
export const AllDexsAssetCtxsRequest = /* @__PURE__ */ (() => {
|
|
11
|
+
return v.pipe(
|
|
12
|
+
v.object({
|
|
13
|
+
/** Type of subscription. */
|
|
14
|
+
type: v.pipe(
|
|
15
|
+
v.literal("allDexsAssetCtxs"),
|
|
16
|
+
v.description("Type of subscription."),
|
|
17
|
+
),
|
|
18
|
+
}),
|
|
19
|
+
v.description("Subscription to asset context events for all DEXs."),
|
|
20
|
+
);
|
|
21
|
+
})();
|
|
22
|
+
export type AllDexsAssetCtxsRequest = v.InferOutput<typeof AllDexsAssetCtxsRequest>;
|
|
23
|
+
|
|
24
|
+
/** Event of asset contexts for all DEXs. */
|
|
25
|
+
export const AllDexsAssetCtxsEvent = /* @__PURE__ */ (() => {
|
|
26
|
+
return v.pipe(
|
|
27
|
+
v.object({
|
|
28
|
+
/** Array of tuples of dex names and contexts for each perpetual asset. */
|
|
29
|
+
ctxs: v.pipe(
|
|
30
|
+
v.array(
|
|
31
|
+
v.tuple([
|
|
32
|
+
v.string(),
|
|
33
|
+
v.array(
|
|
34
|
+
v.object({
|
|
35
|
+
/** Previous day's closing price. */
|
|
36
|
+
prevDayPx: v.pipe(
|
|
37
|
+
UnsignedDecimal,
|
|
38
|
+
v.description("Previous day's closing price."),
|
|
39
|
+
),
|
|
40
|
+
/** Daily notional volume. */
|
|
41
|
+
dayNtlVlm: v.pipe(
|
|
42
|
+
UnsignedDecimal,
|
|
43
|
+
v.description("Daily notional volume."),
|
|
44
|
+
),
|
|
45
|
+
/** Mark price. */
|
|
46
|
+
markPx: v.pipe(
|
|
47
|
+
UnsignedDecimal,
|
|
48
|
+
v.description("Mark price."),
|
|
49
|
+
),
|
|
50
|
+
/** Mid price. */
|
|
51
|
+
midPx: v.pipe(
|
|
52
|
+
v.nullable(UnsignedDecimal),
|
|
53
|
+
v.description("Mid price."),
|
|
54
|
+
),
|
|
55
|
+
/** Funding rate. */
|
|
56
|
+
funding: v.pipe(
|
|
57
|
+
Decimal,
|
|
58
|
+
v.description("Funding rate."),
|
|
59
|
+
),
|
|
60
|
+
/** Total open interest. */
|
|
61
|
+
openInterest: v.pipe(
|
|
62
|
+
UnsignedDecimal,
|
|
63
|
+
v.description("Total open interest."),
|
|
64
|
+
),
|
|
65
|
+
/** Premium price. */
|
|
66
|
+
premium: v.pipe(
|
|
67
|
+
v.nullable(Decimal),
|
|
68
|
+
v.description("Premium price."),
|
|
69
|
+
),
|
|
70
|
+
/** Oracle price. */
|
|
71
|
+
oraclePx: v.pipe(
|
|
72
|
+
UnsignedDecimal,
|
|
73
|
+
v.description("Oracle price."),
|
|
74
|
+
),
|
|
75
|
+
/** Array of impact prices. */
|
|
76
|
+
impactPxs: v.pipe(
|
|
77
|
+
v.nullable(v.array(v.string())),
|
|
78
|
+
v.description("Array of impact prices."),
|
|
79
|
+
),
|
|
80
|
+
/** Daily volume in base currency. */
|
|
81
|
+
dayBaseVlm: v.pipe(
|
|
82
|
+
UnsignedDecimal,
|
|
83
|
+
v.description("Daily volume in base currency."),
|
|
84
|
+
),
|
|
85
|
+
}),
|
|
86
|
+
),
|
|
87
|
+
]),
|
|
88
|
+
),
|
|
89
|
+
v.description("Array of tuples of dex names and contexts for each perpetual asset."),
|
|
90
|
+
),
|
|
91
|
+
}),
|
|
92
|
+
v.description("Event of asset contexts for all DEXs."),
|
|
93
|
+
);
|
|
94
|
+
})();
|
|
95
|
+
export type AllDexsAssetCtxsEvent = v.InferOutput<typeof AllDexsAssetCtxsEvent>;
|
|
96
|
+
|
|
97
|
+
// ============================================================
|
|
98
|
+
// Execution Logic
|
|
99
|
+
// ============================================================
|
|
100
|
+
|
|
101
|
+
import type { SubscriptionConfig } from "./_types.js";
|
|
102
|
+
import type { WebSocketSubscription } from "../../../transport/websocket/mod.js";
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Subscribe to asset contexts for all DEXs.
|
|
106
|
+
*
|
|
107
|
+
* @param config - General configuration for Subscription API subscriptions.
|
|
108
|
+
* @param listener - A callback function to be called when the event is received.
|
|
109
|
+
*
|
|
110
|
+
* @returns A request-promise that resolves with a {@link WebSocketSubscription} object to manage the subscription lifecycle.
|
|
111
|
+
*
|
|
112
|
+
* @throws {ValiError} When the request parameters fail validation (before sending).
|
|
113
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { WebSocketTransport } from "@nktkas/hyperliquid";
|
|
118
|
+
* import { allDexsAssetCtxs } from "@nktkas/hyperliquid/api/subscription";
|
|
119
|
+
*
|
|
120
|
+
* const transport = new WebSocketTransport(); // only `WebSocketTransport`
|
|
121
|
+
*
|
|
122
|
+
* const sub = await allDexsAssetCtxs(
|
|
123
|
+
* { transport },
|
|
124
|
+
* (data) => console.log(data),
|
|
125
|
+
* );
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
129
|
+
*/
|
|
130
|
+
export function allDexsAssetCtxs(
|
|
131
|
+
config: SubscriptionConfig,
|
|
132
|
+
listener: (data: AllDexsAssetCtxsEvent) => void,
|
|
133
|
+
): Promise<WebSocketSubscription> {
|
|
134
|
+
const payload = v.parse(AllDexsAssetCtxsRequest, {
|
|
135
|
+
type: "allDexsAssetCtxs",
|
|
136
|
+
});
|
|
137
|
+
return config.transport.subscribe<AllDexsAssetCtxsEvent>(payload.type, payload, (e) => {
|
|
138
|
+
listener(e.detail);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
// ============================================================
|
|
4
|
+
// API Schemas
|
|
5
|
+
// ============================================================
|
|
6
|
+
|
|
7
|
+
import { Address } from "../../_schemas.js";
|
|
8
|
+
import { ClearinghouseStateResponse } from "../../info/_methods/clearinghouseState.js";
|
|
9
|
+
|
|
10
|
+
/** Subscription to clearinghouse state events for all DEXs for a specific user. */
|
|
11
|
+
export const AllDexsClearinghouseStateRequest = /* @__PURE__ */ (() => {
|
|
12
|
+
return v.pipe(
|
|
13
|
+
v.object({
|
|
14
|
+
/** Type of subscription. */
|
|
15
|
+
type: v.pipe(
|
|
16
|
+
v.literal("allDexsClearinghouseState"),
|
|
17
|
+
v.description("Type of subscription."),
|
|
18
|
+
),
|
|
19
|
+
/** User address. */
|
|
20
|
+
user: v.pipe(
|
|
21
|
+
Address,
|
|
22
|
+
v.description("User address."),
|
|
23
|
+
),
|
|
24
|
+
}),
|
|
25
|
+
v.description("Subscription to clearinghouse state events for all DEXs for a specific user."),
|
|
26
|
+
);
|
|
27
|
+
})();
|
|
28
|
+
export type AllDexsClearinghouseStateRequest = v.InferOutput<typeof AllDexsClearinghouseStateRequest>;
|
|
29
|
+
|
|
30
|
+
/** Event of clearinghouse states for all DEXs for a specific user. */
|
|
31
|
+
export const AllDexsClearinghouseStateEvent = /* @__PURE__ */ (() => {
|
|
32
|
+
return v.pipe(
|
|
33
|
+
v.object({
|
|
34
|
+
/** User address. */
|
|
35
|
+
user: v.pipe(
|
|
36
|
+
Address,
|
|
37
|
+
v.description("User address."),
|
|
38
|
+
),
|
|
39
|
+
/** Array of tuples of dex names and clearinghouse states. */
|
|
40
|
+
clearinghouseStates: v.pipe(
|
|
41
|
+
v.array(
|
|
42
|
+
v.tuple([
|
|
43
|
+
v.string(),
|
|
44
|
+
ClearinghouseStateResponse,
|
|
45
|
+
]),
|
|
46
|
+
),
|
|
47
|
+
v.description("Array of tuples of dex names and clearinghouse states."),
|
|
48
|
+
),
|
|
49
|
+
}),
|
|
50
|
+
v.description("Event of clearinghouse states for all DEXs for a specific user."),
|
|
51
|
+
);
|
|
52
|
+
})();
|
|
53
|
+
export type AllDexsClearinghouseStateEvent = v.InferOutput<typeof AllDexsClearinghouseStateEvent>;
|
|
54
|
+
|
|
55
|
+
// ============================================================
|
|
56
|
+
// Execution Logic
|
|
57
|
+
// ============================================================
|
|
58
|
+
|
|
59
|
+
import type { SubscriptionConfig } from "./_types.js";
|
|
60
|
+
import type { WebSocketSubscription } from "../../../transport/websocket/mod.js";
|
|
61
|
+
|
|
62
|
+
/** Request parameters for the {@linkcode allDexsClearinghouseState} function. */
|
|
63
|
+
export type AllDexsClearinghouseStateParameters = Omit<v.InferInput<typeof AllDexsClearinghouseStateRequest>, "type">;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Subscribe to clearinghouse states for all DEXs for a specific user.
|
|
67
|
+
*
|
|
68
|
+
* @param config - General configuration for Subscription API subscriptions.
|
|
69
|
+
* @param params - Parameters specific to the API subscription.
|
|
70
|
+
* @param listener - A callback function to be called when the event is received.
|
|
71
|
+
*
|
|
72
|
+
* @returns A request-promise that resolves with a {@link WebSocketSubscription} object to manage the subscription lifecycle.
|
|
73
|
+
*
|
|
74
|
+
* @throws {ValiError} When the request parameters fail validation (before sending).
|
|
75
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { WebSocketTransport } from "@nktkas/hyperliquid";
|
|
80
|
+
* import { allDexsClearinghouseState } from "@nktkas/hyperliquid/api/subscription";
|
|
81
|
+
*
|
|
82
|
+
* const transport = new WebSocketTransport(); // only `WebSocketTransport`
|
|
83
|
+
*
|
|
84
|
+
* const sub = await allDexsClearinghouseState(
|
|
85
|
+
* { transport },
|
|
86
|
+
* { user: "0x..." },
|
|
87
|
+
* (data) => console.log(data),
|
|
88
|
+
* );
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
|
|
92
|
+
*/
|
|
93
|
+
export function allDexsClearinghouseState(
|
|
94
|
+
config: SubscriptionConfig,
|
|
95
|
+
params: AllDexsClearinghouseStateParameters,
|
|
96
|
+
listener: (data: AllDexsClearinghouseStateEvent) => void,
|
|
97
|
+
): Promise<WebSocketSubscription> {
|
|
98
|
+
const payload = v.parse(AllDexsClearinghouseStateRequest, {
|
|
99
|
+
type: "allDexsClearinghouseState",
|
|
100
|
+
...params,
|
|
101
|
+
});
|
|
102
|
+
return config.transport.subscribe<AllDexsClearinghouseStateEvent>(payload.type, payload, (e) => {
|
|
103
|
+
listener(e.detail);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -16,6 +16,12 @@ import {
|
|
|
16
16
|
type ActiveSpotAssetCtxEvent,
|
|
17
17
|
type ActiveSpotAssetCtxParameters,
|
|
18
18
|
} from "./_methods/activeSpotAssetCtx.js";
|
|
19
|
+
import { allDexsAssetCtxs, type AllDexsAssetCtxsEvent } from "./_methods/allDexsAssetCtxs.js";
|
|
20
|
+
import {
|
|
21
|
+
allDexsClearinghouseState,
|
|
22
|
+
type AllDexsClearinghouseStateEvent,
|
|
23
|
+
type AllDexsClearinghouseStateParameters,
|
|
24
|
+
} from "./_methods/allDexsClearinghouseState.js";
|
|
19
25
|
import { allMids, type AllMidsEvent, type AllMidsParameters } from "./_methods/allMids.js";
|
|
20
26
|
import { assetCtxs, type AssetCtxsEvent, type AssetCtxsParameters } from "./_methods/assetCtxs.js";
|
|
21
27
|
import { bbo, type BboEvent, type BboParameters } from "./_methods/bbo.js";
|
|
@@ -112,6 +118,21 @@ export class SubscriptionClient<C extends SubscriptionConfig = SubscriptionConfi
|
|
|
112
118
|
return activeSpotAssetCtx(this.config_, params, listener);
|
|
113
119
|
}
|
|
114
120
|
|
|
121
|
+
/** @see {@link allDexsAssetCtxs} */
|
|
122
|
+
allDexsAssetCtxs(
|
|
123
|
+
listener: (data: AllDexsAssetCtxsEvent) => void,
|
|
124
|
+
): Promise<WebSocketSubscription> {
|
|
125
|
+
return allDexsAssetCtxs(this.config_, listener);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @see {@link allDexsClearinghouseState} */
|
|
129
|
+
allDexsClearinghouseState(
|
|
130
|
+
params: AllDexsClearinghouseStateParameters,
|
|
131
|
+
listener: (data: AllDexsClearinghouseStateEvent) => void,
|
|
132
|
+
): Promise<WebSocketSubscription> {
|
|
133
|
+
return allDexsClearinghouseState(this.config_, params, listener);
|
|
134
|
+
}
|
|
135
|
+
|
|
115
136
|
/** @see {@link allMids} */
|
|
116
137
|
allMids(
|
|
117
138
|
listener: (data: AllMidsEvent) => void,
|
|
@@ -330,6 +351,11 @@ export type {
|
|
|
330
351
|
ActiveSpotAssetCtxEvent as ActiveSpotAssetCtxWsEvent,
|
|
331
352
|
ActiveSpotAssetCtxParameters as ActiveSpotAssetCtxWsParameters,
|
|
332
353
|
} from "./_methods/activeSpotAssetCtx.js";
|
|
354
|
+
export type { AllDexsAssetCtxsEvent as AllDexsAssetCtxsWsEvent } from "./_methods/allDexsAssetCtxs.js";
|
|
355
|
+
export type {
|
|
356
|
+
AllDexsClearinghouseStateEvent as AllDexsClearinghouseStateWsEvent,
|
|
357
|
+
AllDexsClearinghouseStateParameters as AllDexsClearinghouseStateWsParameters,
|
|
358
|
+
} from "./_methods/allDexsClearinghouseState.js";
|
|
333
359
|
export type { AllMidsEvent as AllMidsWsEvent, AllMidsParameters as AllMidsWsParameters } from "./_methods/allMids.js";
|
|
334
360
|
export type {
|
|
335
361
|
AssetCtxsEvent as AssetCtxsWsEvent,
|
|
@@ -28,6 +28,8 @@ export type { SubscriptionConfig } from "./_methods/_types.js";
|
|
|
28
28
|
export * from "./_methods/activeAssetCtx.js";
|
|
29
29
|
export * from "./_methods/activeAssetData.js";
|
|
30
30
|
export * from "./_methods/activeSpotAssetCtx.js";
|
|
31
|
+
export * from "./_methods/allDexsAssetCtxs.js";
|
|
32
|
+
export * from "./_methods/allDexsClearinghouseState.js";
|
|
31
33
|
export * from "./_methods/allMids.js";
|
|
32
34
|
export * from "./_methods/assetCtxs.js";
|
|
33
35
|
export * from "./_methods/bbo.js";
|