@hfunlabs/hyperliquid 0.27.1-hfunlabs.1 → 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.
Files changed (55) hide show
  1. package/esm/src/api/info/l4Orders.d.ts +204 -0
  2. package/esm/src/api/info/l4Orders.d.ts.map +1 -0
  3. package/esm/src/api/info/l4Orders.js +103 -0
  4. package/esm/src/api/info/l4Orders.js.map +1 -0
  5. package/esm/src/api/info/~client.d.ts +22 -0
  6. package/esm/src/api/info/~client.d.ts.map +1 -1
  7. package/esm/src/api/info/~client.js +23 -0
  8. package/esm/src/api/info/~client.js.map +1 -1
  9. package/esm/src/api/info/~mod.d.ts +1 -0
  10. package/esm/src/api/info/~mod.d.ts.map +1 -1
  11. package/esm/src/api/info/~mod.js +1 -0
  12. package/esm/src/api/info/~mod.js.map +1 -1
  13. package/esm/src/api/subscription/allDexsClearinghouseState.d.ts +322 -0
  14. package/esm/src/api/subscription/allDexsClearinghouseState.d.ts.map +1 -0
  15. package/esm/src/api/subscription/allDexsClearinghouseState.js +69 -0
  16. package/esm/src/api/subscription/allDexsClearinghouseState.js.map +1 -0
  17. package/esm/src/api/subscription/~client.d.ts +22 -0
  18. package/esm/src/api/subscription/~client.d.ts.map +1 -1
  19. package/esm/src/api/subscription/~client.js +23 -0
  20. package/esm/src/api/subscription/~client.js.map +1 -1
  21. package/esm/src/api/subscription/~mod.d.ts +1 -0
  22. package/esm/src/api/subscription/~mod.d.ts.map +1 -1
  23. package/esm/src/api/subscription/~mod.js +1 -0
  24. package/esm/src/api/subscription/~mod.js.map +1 -1
  25. package/package.json +1 -1
  26. package/script/src/api/info/l4Orders.d.ts +204 -0
  27. package/script/src/api/info/l4Orders.d.ts.map +1 -0
  28. package/script/src/api/info/l4Orders.js +140 -0
  29. package/script/src/api/info/l4Orders.js.map +1 -0
  30. package/script/src/api/info/~client.d.ts +22 -0
  31. package/script/src/api/info/~client.d.ts.map +1 -1
  32. package/script/src/api/info/~client.js +23 -0
  33. package/script/src/api/info/~client.js.map +1 -1
  34. package/script/src/api/info/~mod.d.ts +1 -0
  35. package/script/src/api/info/~mod.d.ts.map +1 -1
  36. package/script/src/api/info/~mod.js +1 -0
  37. package/script/src/api/info/~mod.js.map +1 -1
  38. package/script/src/api/subscription/allDexsClearinghouseState.d.ts +322 -0
  39. package/script/src/api/subscription/allDexsClearinghouseState.d.ts.map +1 -0
  40. package/script/src/api/subscription/allDexsClearinghouseState.js +106 -0
  41. package/script/src/api/subscription/allDexsClearinghouseState.js.map +1 -0
  42. package/script/src/api/subscription/~client.d.ts +22 -0
  43. package/script/src/api/subscription/~client.d.ts.map +1 -1
  44. package/script/src/api/subscription/~client.js +23 -0
  45. package/script/src/api/subscription/~client.js.map +1 -1
  46. package/script/src/api/subscription/~mod.d.ts +1 -0
  47. package/script/src/api/subscription/~mod.d.ts.map +1 -1
  48. package/script/src/api/subscription/~mod.js +1 -0
  49. package/script/src/api/subscription/~mod.js.map +1 -1
  50. package/src/src/api/info/l4Orders.ts +195 -0
  51. package/src/src/api/info/~client.ts +27 -0
  52. package/src/src/api/info/~mod.ts +1 -0
  53. package/src/src/api/subscription/allDexsClearinghouseState.ts +109 -0
  54. package/src/src/api/subscription/~client.ts +30 -0
  55. package/src/src/api/subscription/~mod.ts +1 -0
@@ -0,0 +1,195 @@
1
+ import * as v from "valibot";
2
+
3
+ // ============================================================
4
+ // API Schemas
5
+ // ============================================================
6
+
7
+ import { Address, type DeepImmutable, parser, UnsignedDecimal, UnsignedInteger } from "../_base.js";
8
+
9
+ /** L4 order details. */
10
+ export const L4OrderSchema = /* @__PURE__ */ (() => {
11
+ return v.pipe(
12
+ v.object({
13
+ /** User address. */
14
+ user: v.pipe(
15
+ Address,
16
+ v.description("User address."),
17
+ ),
18
+ /** Asset symbol. */
19
+ coin: v.pipe(
20
+ v.string(),
21
+ v.description("Asset symbol."),
22
+ ),
23
+ /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
24
+ side: v.pipe(
25
+ v.union([v.literal("B"), v.literal("A")]),
26
+ v.description('Order side ("B" = Bid/Buy, "A" = Ask/Sell).'),
27
+ ),
28
+ /** Limit price. */
29
+ limitPx: v.pipe(
30
+ UnsignedDecimal,
31
+ v.description("Limit price."),
32
+ ),
33
+ /** Size. */
34
+ sz: v.pipe(
35
+ UnsignedDecimal,
36
+ v.description("Size."),
37
+ ),
38
+ /** Order ID. */
39
+ oid: v.pipe(
40
+ UnsignedInteger,
41
+ v.description("Order ID."),
42
+ ),
43
+ /** Timestamp when the order was placed (in ms since epoch). */
44
+ timestamp: v.pipe(
45
+ UnsignedInteger,
46
+ v.description("Timestamp when the order was placed (in ms since epoch)."),
47
+ ),
48
+ /** Condition for triggering the order. */
49
+ triggerCondition: v.pipe(
50
+ v.string(),
51
+ v.description("Condition for triggering the order."),
52
+ ),
53
+ /** Indicates if the order is a trigger order. */
54
+ isTrigger: v.pipe(
55
+ v.boolean(),
56
+ v.description("Indicates if the order is a trigger order."),
57
+ ),
58
+ /** Trigger price. */
59
+ triggerPx: v.pipe(
60
+ UnsignedDecimal,
61
+ v.description("Trigger price."),
62
+ ),
63
+ /** Indicates if the order is a position TP/SL order. */
64
+ isPositionTpsl: v.pipe(
65
+ v.boolean(),
66
+ v.description("Indicates if the order is a position TP/SL order."),
67
+ ),
68
+ /** Indicates whether the order is reduce-only. */
69
+ reduceOnly: v.pipe(
70
+ v.boolean(),
71
+ v.description("Indicates whether the order is reduce-only."),
72
+ ),
73
+ /**
74
+ * Order type for market execution.
75
+ * - `"Market"`: Executes immediately at the market price.
76
+ * - `"Limit"`: Executes at the specified limit price or better.
77
+ * - `"Stop Market"`: Activates as a market order when a stop price is reached.
78
+ * - `"Stop Limit"`: Activates as a limit order when a stop price is reached.
79
+ * - `"Take Profit Market"`: Executes as a market order when a take profit price is reached.
80
+ * - `"Take Profit Limit"`: Executes as a limit order when a take profit price is reached.
81
+ */
82
+ orderType: v.pipe(
83
+ v.string(),
84
+ v.description("Order type for market execution."),
85
+ ),
86
+ /** Time-in-force option (e.g., "Gtc", "Ioc", "Alo"). */
87
+ tif: v.pipe(
88
+ v.nullable(v.string()),
89
+ v.description("Time-in-force option."),
90
+ ),
91
+ /** Client Order ID. */
92
+ cloid: v.pipe(
93
+ v.nullable(v.string()),
94
+ v.description("Client Order ID."),
95
+ ),
96
+ }),
97
+ v.description("L4 order details."),
98
+ );
99
+ })();
100
+
101
+ /**
102
+ * Request L4 orders at a specific price level.
103
+ */
104
+ export const L4OrdersRequest = /* @__PURE__ */ (() => {
105
+ return v.pipe(
106
+ v.object({
107
+ /** Type of request. */
108
+ type: v.pipe(
109
+ v.literal("l4Orders"),
110
+ v.description("Type of request."),
111
+ ),
112
+ /** Asset symbol (e.g., ETH). */
113
+ coin: v.pipe(
114
+ v.string(),
115
+ v.description("Asset symbol (e.g., ETH)."),
116
+ ),
117
+ /** Price level to query orders at. */
118
+ px: v.pipe(
119
+ UnsignedDecimal,
120
+ v.description("Price level to query orders at."),
121
+ ),
122
+ }),
123
+ v.description("Request L4 orders at a specific price level."),
124
+ );
125
+ })();
126
+ export type L4OrdersRequest = v.InferOutput<typeof L4OrdersRequest>;
127
+
128
+ /**
129
+ * L4 orders snapshot at a specific price level.
130
+ */
131
+ export const L4OrdersResponse = /* @__PURE__ */ (() => {
132
+ return v.pipe(
133
+ v.object({
134
+ /** Asset symbol. */
135
+ coin: v.pipe(
136
+ v.string(),
137
+ v.description("Asset symbol."),
138
+ ),
139
+ /** Timestamp of the snapshot (in ms since epoch). */
140
+ time: v.pipe(
141
+ UnsignedInteger,
142
+ v.description("Timestamp of the snapshot (in ms since epoch)."),
143
+ ),
144
+ /** Array of L4 orders at this price level. */
145
+ orders: v.pipe(
146
+ v.array(L4OrderSchema),
147
+ v.description("Array of L4 orders at this price level."),
148
+ ),
149
+ }),
150
+ v.description("L4 orders snapshot at a specific price level."),
151
+ );
152
+ })();
153
+ export type L4OrdersResponse = v.InferOutput<typeof L4OrdersResponse>;
154
+
155
+ // ============================================================
156
+ // Execution Logic
157
+ // ============================================================
158
+
159
+ import type { InfoRequestConfig } from "./_types.js";
160
+
161
+ /** Request parameters for the {@linkcode l4Orders} function. */
162
+ export type L4OrdersParameters = Omit<v.InferInput<typeof L4OrdersRequest>, "type">;
163
+
164
+ /**
165
+ * Request L4 orders at a specific price level.
166
+ * @param config - General configuration for Info API requests.
167
+ * @param params - Parameters specific to the API request.
168
+ * @param signal - An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) can be used to cancel the request by calling [`abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) on the corresponding [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
169
+ * @returns L4 orders snapshot at a specific price level.
170
+ *
171
+ * @throws {TransportError} When the transport layer throws an error.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * import { HttpTransport } from "@nktkas/hyperliquid";
176
+ * import { l4Orders } from "@nktkas/hyperliquid/api/info";
177
+ *
178
+ * const transport = new HttpTransport(); // or `WebSocketTransport`
179
+ * const data = await l4Orders(
180
+ * { transport },
181
+ * { coin: "ETH", px: "1000" },
182
+ * );
183
+ * ```
184
+ */
185
+ export function l4Orders(
186
+ config: InfoRequestConfig,
187
+ params: DeepImmutable<L4OrdersParameters>,
188
+ signal?: AbortSignal,
189
+ ): Promise<L4OrdersResponse> {
190
+ const request = parser(L4OrdersRequest)({
191
+ type: "l4Orders",
192
+ ...params,
193
+ });
194
+ return config.transport.request("info", request, signal);
195
+ }
@@ -21,6 +21,7 @@ import { gossipRootIps } from "./gossipRootIps.js";
21
21
  import { historicalOrders } from "./historicalOrders.js";
22
22
  import { isVip } from "./isVip.js";
23
23
  import { l2Book } from "./l2Book.js";
24
+ import { l4Orders } from "./l4Orders.js";
24
25
  import { leadingVaults } from "./leadingVaults.js";
25
26
  import { legalCheck } from "./legalCheck.js";
26
27
  import { liquidatable } from "./liquidatable.js";
@@ -574,6 +575,31 @@ export class InfoClient<T extends IRequestTransport = IRequestTransport> impleme
574
575
  return l2Book(this, ...args);
575
576
  }
576
577
 
578
+ /**
579
+ * Request L4 orders at a specific price level.
580
+ * @param params - Parameters specific to the API request.
581
+ * @param signal - An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) can be used to cancel the request by calling [`abort()`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) on the corresponding [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
582
+ * @returns L4 orders snapshot at a specific price level.
583
+ *
584
+ * @throws {TransportError} When the transport layer throws an error.
585
+ *
586
+ * @see null
587
+ * @example
588
+ * ```ts
589
+ * import * as hl from "@nktkas/hyperliquid";
590
+ *
591
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
592
+ *
593
+ * const client = new hl.InfoClient({ transport });
594
+ * const data = await client.l4Orders({ coin: "ETH", px: "1000" });
595
+ * ```
596
+ */
597
+ l4Orders(
598
+ ...args: OmitFirst<OverloadedParameters<typeof l4Orders>>
599
+ ): ReturnType<typeof l4Orders> {
600
+ return l4Orders(this, ...args);
601
+ }
602
+
577
603
  /**
578
604
  * Request leading vaults for a user.
579
605
  * @param params - Parameters specific to the API request.
@@ -1783,6 +1809,7 @@ export type * from "./gossipRootIps.js";
1783
1809
  export type * from "./historicalOrders.js";
1784
1810
  export type * from "./isVip.js";
1785
1811
  export type * from "./l2Book.js";
1812
+ export type * from "./l4Orders.js";
1786
1813
  export type * from "./leadingVaults.js";
1787
1814
  export type * from "./legalCheck.js";
1788
1815
  export type * from "./liquidatable.js";
@@ -43,6 +43,7 @@ export * from "./gossipRootIps.js";
43
43
  export * from "./historicalOrders.js";
44
44
  export * from "./isVip.js";
45
45
  export * from "./l2Book.js";
46
+ export * from "./l4Orders.js";
46
47
  export * from "./leadingVaults.js";
47
48
  export * from "./legalCheck.js";
48
49
  export * from "./liquidatable.js";
@@ -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";