@hfunlabs/hyperliquid 0.27.1-hfunlabs.2 → 0.27.1-hfunlabs.3
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/subscription/allDexsClearinghouseState.d.ts +322 -0
- package/esm/src/api/subscription/allDexsClearinghouseState.d.ts.map +1 -0
- package/esm/src/api/subscription/allDexsClearinghouseState.js +69 -0
- package/esm/src/api/subscription/allDexsClearinghouseState.js.map +1 -0
- package/esm/src/api/subscription/~client.d.ts +22 -0
- package/esm/src/api/subscription/~client.d.ts.map +1 -1
- package/esm/src/api/subscription/~client.js +23 -0
- package/esm/src/api/subscription/~client.js.map +1 -1
- package/esm/src/api/subscription/~mod.d.ts +1 -0
- package/esm/src/api/subscription/~mod.d.ts.map +1 -1
- package/esm/src/api/subscription/~mod.js +1 -0
- package/esm/src/api/subscription/~mod.js.map +1 -1
- package/package.json +1 -1
- package/script/src/api/subscription/allDexsClearinghouseState.d.ts +322 -0
- package/script/src/api/subscription/allDexsClearinghouseState.d.ts.map +1 -0
- package/script/src/api/subscription/allDexsClearinghouseState.js +106 -0
- package/script/src/api/subscription/allDexsClearinghouseState.js.map +1 -0
- package/script/src/api/subscription/~client.d.ts +22 -0
- package/script/src/api/subscription/~client.d.ts.map +1 -1
- package/script/src/api/subscription/~client.js +23 -0
- package/script/src/api/subscription/~client.js.map +1 -1
- package/script/src/api/subscription/~mod.d.ts +1 -0
- package/script/src/api/subscription/~mod.d.ts.map +1 -1
- package/script/src/api/subscription/~mod.js +1 -0
- package/script/src/api/subscription/~mod.js.map +1 -1
- package/src/src/api/subscription/allDexsClearinghouseState.ts +109 -0
- package/src/src/api/subscription/~client.ts +30 -0
- package/src/src/api/subscription/~mod.ts +1 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
// ============================================================
|
|
4
|
+
// API Schemas
|
|
5
|
+
// ============================================================
|
|
6
|
+
|
|
7
|
+
import { Address } from "../_base.js";
|
|
8
|
+
import { ClearinghouseStateResponse } from "../info/clearinghouseState.js";
|
|
9
|
+
|
|
10
|
+
/** Subscription to clearinghouse state events across all DEXes 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 across all DEXes for a specific user."),
|
|
26
|
+
);
|
|
27
|
+
})();
|
|
28
|
+
export type AllDexsClearinghouseStateRequest = v.InferOutput<typeof AllDexsClearinghouseStateRequest>;
|
|
29
|
+
|
|
30
|
+
/** Event of clearinghouse state across all DEXes 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 containing DEX name and clearinghouse state. Empty string represents main DEX. */
|
|
40
|
+
clearinghouseStates: v.pipe(
|
|
41
|
+
v.array(
|
|
42
|
+
v.tuple([
|
|
43
|
+
/** DEX name (empty string for main dex). */
|
|
44
|
+
v.pipe(
|
|
45
|
+
v.string(),
|
|
46
|
+
v.description("DEX name (empty string for main dex)."),
|
|
47
|
+
),
|
|
48
|
+
/** Account summary for perpetual trading. */
|
|
49
|
+
ClearinghouseStateResponse,
|
|
50
|
+
]),
|
|
51
|
+
),
|
|
52
|
+
v.description("Array of tuples containing DEX name and clearinghouse state. Empty string represents main DEX."),
|
|
53
|
+
),
|
|
54
|
+
}),
|
|
55
|
+
v.description("Event of clearinghouse state across all DEXes for a specific user."),
|
|
56
|
+
);
|
|
57
|
+
})();
|
|
58
|
+
export type AllDexsClearinghouseStateEvent = v.InferOutput<typeof AllDexsClearinghouseStateEvent>;
|
|
59
|
+
|
|
60
|
+
// ============================================================
|
|
61
|
+
// Execution Logic
|
|
62
|
+
// ============================================================
|
|
63
|
+
|
|
64
|
+
import { type DeepImmutable, parser } from "../_base.js";
|
|
65
|
+
import type { SubscriptionRequestConfig } from "./_types.js";
|
|
66
|
+
import type { Subscription } from "../../transport/base.js";
|
|
67
|
+
|
|
68
|
+
/** Request parameters for the {@linkcode allDexsClearinghouseState} function. */
|
|
69
|
+
export type AllDexsClearinghouseStateParameters = Omit<v.InferInput<typeof AllDexsClearinghouseStateRequest>, "type">;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Subscribe to clearinghouse state updates across all DEXes for a specific user.
|
|
73
|
+
* @param config - General configuration for Subscription API subscriptions.
|
|
74
|
+
* @param params - Parameters specific to the API subscription.
|
|
75
|
+
* @param listener - A callback function to be called when the event is received.
|
|
76
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
77
|
+
*
|
|
78
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
79
|
+
*
|
|
80
|
+
* @see null
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { WebSocketTransport } from "@nktkas/hyperliquid";
|
|
84
|
+
* import { allDexsClearinghouseState } from "@nktkas/hyperliquid/api/subscription";
|
|
85
|
+
*
|
|
86
|
+
* const transport = new WebSocketTransport();
|
|
87
|
+
*
|
|
88
|
+
* const sub = await allDexsClearinghouseState(
|
|
89
|
+
* { transport },
|
|
90
|
+
* { user: "0x..." },
|
|
91
|
+
* (data) => console.log(data),
|
|
92
|
+
* );
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export function allDexsClearinghouseState(
|
|
96
|
+
config: SubscriptionRequestConfig,
|
|
97
|
+
params: DeepImmutable<AllDexsClearinghouseStateParameters>,
|
|
98
|
+
listener: (data: AllDexsClearinghouseStateEvent) => void,
|
|
99
|
+
): Promise<Subscription> {
|
|
100
|
+
const payload = parser(AllDexsClearinghouseStateRequest)({
|
|
101
|
+
type: "allDexsClearinghouseState",
|
|
102
|
+
...params,
|
|
103
|
+
});
|
|
104
|
+
return config.transport.subscribe<AllDexsClearinghouseStateEvent>(payload.type, payload, (e) => {
|
|
105
|
+
if (e.detail.user === payload.user) {
|
|
106
|
+
listener(e.detail);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -5,6 +5,7 @@ import type { SubscriptionRequestConfig } from "./_types.js";
|
|
|
5
5
|
import { activeAssetCtx } from "./activeAssetCtx.js";
|
|
6
6
|
import { activeAssetData } from "./activeAssetData.js";
|
|
7
7
|
import { activeSpotAssetCtx } from "./activeSpotAssetCtx.js";
|
|
8
|
+
import { allDexsClearinghouseState } from "./allDexsClearinghouseState.js";
|
|
8
9
|
import { allMids } from "./allMids.js";
|
|
9
10
|
import { assetCtxs } from "./assetCtxs.js";
|
|
10
11
|
import { bbo } from "./bbo.js";
|
|
@@ -41,6 +42,10 @@ export type {
|
|
|
41
42
|
ActiveSpotAssetCtxEvent as WsActiveSpotAssetCtxEvent,
|
|
42
43
|
ActiveSpotAssetCtxParameters as WsActiveSpotAssetCtxParameters,
|
|
43
44
|
} from "./activeSpotAssetCtx.js";
|
|
45
|
+
export type {
|
|
46
|
+
AllDexsClearinghouseStateEvent as WsAllDexsClearinghouseStateEvent,
|
|
47
|
+
AllDexsClearinghouseStateParameters as WsAllDexsClearinghouseStateParameters,
|
|
48
|
+
} from "./allDexsClearinghouseState.js";
|
|
44
49
|
export type { AllMidsEvent as WsAllMidsEvent, AllMidsParameters as WsAllMidsParameters } from "./allMids.js";
|
|
45
50
|
export type { AssetCtxsEvent as WsAssetCtxsEvent, AssetCtxsParameters as WsAssetCtxsParameters } from "./assetCtxs.js";
|
|
46
51
|
export type { BboEvent as WsBboEvent, BboParameters as WsBboParameters } from "./bbo.js";
|
|
@@ -206,6 +211,31 @@ export class SubscriptionClient<
|
|
|
206
211
|
return activeSpotAssetCtx(this, ...args);
|
|
207
212
|
}
|
|
208
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Subscribe to clearinghouse state updates across all DEXes for a specific user.
|
|
216
|
+
* @param params - Parameters specific to the API subscription.
|
|
217
|
+
* @param listener - A callback function to be called when the event is received.
|
|
218
|
+
* @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
|
|
219
|
+
*
|
|
220
|
+
* @throws {TransportError} When the transport layer throws an error.
|
|
221
|
+
*
|
|
222
|
+
* @see null
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* import * as hl from "@nktkas/hyperliquid";
|
|
226
|
+
*
|
|
227
|
+
* const transport = new hl.WebSocketTransport();
|
|
228
|
+
*
|
|
229
|
+
* const client = new hl.SubscriptionClient({ transport });
|
|
230
|
+
* const sub = await client.allDexsClearinghouseState({ user: "0x..." }, (data) => console.log(data));
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
allDexsClearinghouseState(
|
|
234
|
+
...args: OmitFirst<OverloadedParameters<typeof allDexsClearinghouseState>>
|
|
235
|
+
): ReturnType<typeof allDexsClearinghouseState> {
|
|
236
|
+
return allDexsClearinghouseState(this, ...args);
|
|
237
|
+
}
|
|
238
|
+
|
|
209
239
|
/**
|
|
210
240
|
* Subscribe to mid prices for all actively traded assets.
|
|
211
241
|
* @param params - Parameters specific to the API subscription.
|
|
@@ -29,6 +29,7 @@ export type { SubscriptionRequestConfig } from "./_types.js";
|
|
|
29
29
|
export * from "./activeAssetCtx.js";
|
|
30
30
|
export * from "./activeAssetData.js";
|
|
31
31
|
export * from "./activeSpotAssetCtx.js";
|
|
32
|
+
export * from "./allDexsClearinghouseState.js";
|
|
32
33
|
export * from "./allMids.js";
|
|
33
34
|
export * from "./assetCtxs.js";
|
|
34
35
|
export * from "./bbo.js";
|