@hfunlabs/hyperliquid 0.27.1-hfunlabs.3 → 0.27.1-hfunlabs.5

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 (37) hide show
  1. package/esm/src/api/info/l3Orders.d.ts +184 -0
  2. package/esm/src/api/info/l3Orders.d.ts.map +1 -0
  3. package/esm/src/api/info/l3Orders.js +110 -0
  4. package/esm/src/api/info/l3Orders.js.map +1 -0
  5. package/esm/src/api/info/l4Orders.d.ts +25 -9
  6. package/esm/src/api/info/l4Orders.d.ts.map +1 -1
  7. package/esm/src/api/info/l4Orders.js +34 -8
  8. package/esm/src/api/info/l4Orders.js.map +1 -1
  9. package/esm/src/api/info/~client.d.ts +25 -3
  10. package/esm/src/api/info/~client.d.ts.map +1 -1
  11. package/esm/src/api/info/~client.js +26 -3
  12. package/esm/src/api/info/~client.js.map +1 -1
  13. package/esm/src/api/info/~mod.d.ts +1 -0
  14. package/esm/src/api/info/~mod.d.ts.map +1 -1
  15. package/esm/src/api/info/~mod.js +1 -0
  16. package/esm/src/api/info/~mod.js.map +1 -1
  17. package/package.json +1 -1
  18. package/script/src/api/info/l3Orders.d.ts +184 -0
  19. package/script/src/api/info/l3Orders.d.ts.map +1 -0
  20. package/script/src/api/info/l3Orders.js +147 -0
  21. package/script/src/api/info/l3Orders.js.map +1 -0
  22. package/script/src/api/info/l4Orders.d.ts +25 -9
  23. package/script/src/api/info/l4Orders.d.ts.map +1 -1
  24. package/script/src/api/info/l4Orders.js +35 -9
  25. package/script/src/api/info/l4Orders.js.map +1 -1
  26. package/script/src/api/info/~client.d.ts +25 -3
  27. package/script/src/api/info/~client.d.ts.map +1 -1
  28. package/script/src/api/info/~client.js +26 -3
  29. package/script/src/api/info/~client.js.map +1 -1
  30. package/script/src/api/info/~mod.d.ts +1 -0
  31. package/script/src/api/info/~mod.d.ts.map +1 -1
  32. package/script/src/api/info/~mod.js +1 -0
  33. package/script/src/api/info/~mod.js.map +1 -1
  34. package/src/src/api/info/l3Orders.ts +201 -0
  35. package/src/src/api/info/l4Orders.ts +54 -11
  36. package/src/src/api/info/~client.ts +30 -3
  37. package/src/src/api/info/~mod.ts +1 -0
@@ -0,0 +1,201 @@
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
+ /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
10
+ export const SideSchema = /* @__PURE__ */ (() => {
11
+ return v.pipe(
12
+ v.union([v.literal("B"), v.literal("A")]),
13
+ v.description('Order side ("B" = Bid/Buy, "A" = Ask/Sell).'),
14
+ );
15
+ })();
16
+ export type Side = v.InferOutput<typeof SideSchema>;
17
+
18
+ /** L3 order details. */
19
+ export const L3OrderSchema = /* @__PURE__ */ (() => {
20
+ return v.pipe(
21
+ v.object({
22
+ /** User address. */
23
+ user: v.pipe(
24
+ Address,
25
+ v.description("User address."),
26
+ ),
27
+ /** Asset symbol. */
28
+ coin: v.pipe(
29
+ v.string(),
30
+ v.description("Asset symbol."),
31
+ ),
32
+ /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
33
+ side: v.pipe(
34
+ SideSchema,
35
+ v.description('Order side ("B" = Bid/Buy, "A" = Ask/Sell).'),
36
+ ),
37
+ /** Limit price. */
38
+ limitPx: v.pipe(
39
+ UnsignedDecimal,
40
+ v.description("Limit price."),
41
+ ),
42
+ /** Size. */
43
+ sz: v.pipe(
44
+ UnsignedDecimal,
45
+ v.description("Size."),
46
+ ),
47
+ /** Order ID. */
48
+ oid: v.pipe(
49
+ UnsignedInteger,
50
+ v.description("Order ID."),
51
+ ),
52
+ /** Timestamp when the order was placed (in ms since epoch). */
53
+ timestamp: v.pipe(
54
+ UnsignedInteger,
55
+ v.description("Timestamp when the order was placed (in ms since epoch)."),
56
+ ),
57
+ }),
58
+ v.description("L3 order details."),
59
+ );
60
+ })();
61
+ export type L3Order = v.InferOutput<typeof L3OrderSchema>;
62
+
63
+ /**
64
+ * Request L3 orders within a price range.
65
+ */
66
+ export const L3OrdersRequest = /* @__PURE__ */ (() => {
67
+ return v.pipe(
68
+ v.object({
69
+ /** Type of request. */
70
+ type: v.pipe(
71
+ v.literal("l3Orders"),
72
+ v.description("Type of request."),
73
+ ),
74
+ /** Asset symbol (e.g., BTC). */
75
+ coin: v.pipe(
76
+ v.string(),
77
+ v.description("Asset symbol (e.g., BTC)."),
78
+ ),
79
+ /** Minimum price (inclusive). */
80
+ pxMin: v.pipe(
81
+ UnsignedDecimal,
82
+ v.description("Minimum price (inclusive)."),
83
+ ),
84
+ /** Maximum price (inclusive). */
85
+ pxMax: v.pipe(
86
+ UnsignedDecimal,
87
+ v.description("Maximum price (inclusive)."),
88
+ ),
89
+ }),
90
+ v.description("Request L3 orders within a price range."),
91
+ );
92
+ })();
93
+ export type L3OrdersRequest = v.InferOutput<typeof L3OrdersRequest>;
94
+
95
+ /**
96
+ * L3 orders within a price range.
97
+ */
98
+ export const L3OrdersResponse = /* @__PURE__ */ (() => {
99
+ return v.pipe(
100
+ v.object({
101
+ /** Asset symbol. */
102
+ coin: v.pipe(
103
+ v.string(),
104
+ v.description("Asset symbol."),
105
+ ),
106
+ /** Timestamp of the snapshot (in ms since epoch). */
107
+ time: v.pipe(
108
+ UnsignedInteger,
109
+ v.description("Timestamp of the snapshot (in ms since epoch)."),
110
+ ),
111
+ /** Bid and ask orders (index 0 = bids, index 1 = asks). */
112
+ orders: v.pipe(
113
+ v.tuple([v.array(L3OrderSchema), v.array(L3OrderSchema)]),
114
+ v.description("Bid and ask orders (index 0 = bids, index 1 = asks)."),
115
+ ),
116
+ }),
117
+ v.description("L3 orders snapshot for a price range."),
118
+ );
119
+ })();
120
+ export type L3OrdersResponse = v.InferOutput<typeof L3OrdersResponse>;
121
+
122
+ // ============================================================
123
+ // Execution Logic
124
+ // ============================================================
125
+
126
+ import type { InfoRequestConfig } from "./_types.js";
127
+
128
+ /** Request parameters for the {@linkcode l3Orders} function. */
129
+ export const L3OrdersParametersSchema = /* @__PURE__ */ (() => {
130
+ return v.union([
131
+ v.object({
132
+ /** Asset symbol (e.g., BTC). */
133
+ coin: v.pipe(
134
+ v.string(),
135
+ v.description("Asset symbol (e.g., BTC)."),
136
+ ),
137
+ /** Price level to query orders at. (Deprecated; use `pxMin`/`pxMax`.) */
138
+ px: v.pipe(
139
+ UnsignedDecimal,
140
+ v.description("Price level to query orders at. (Deprecated; use `pxMin`/`pxMax`.)"),
141
+ ),
142
+ }),
143
+ v.object({
144
+ /** Asset symbol (e.g., BTC). */
145
+ coin: v.pipe(
146
+ v.string(),
147
+ v.description("Asset symbol (e.g., BTC)."),
148
+ ),
149
+ /** Minimum price (inclusive). */
150
+ pxMin: v.pipe(
151
+ UnsignedDecimal,
152
+ v.description("Minimum price (inclusive)."),
153
+ ),
154
+ /** Maximum price (inclusive). */
155
+ pxMax: v.pipe(
156
+ UnsignedDecimal,
157
+ v.description("Maximum price (inclusive)."),
158
+ ),
159
+ }),
160
+ ]);
161
+ })();
162
+ export type L3OrdersParameters = v.InferInput<typeof L3OrdersParametersSchema>;
163
+
164
+ /**
165
+ * Request L3 orders within a price range.
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 L3 orders snapshot for a price range.
170
+ *
171
+ * @throws {TransportError} When the transport layer throws an error.
172
+ *
173
+ * @see null
174
+ * @example
175
+ * ```ts
176
+ * import { HttpTransport } from "@nktkas/hyperliquid";
177
+ * import { l3Orders } from "@nktkas/hyperliquid/api/info";
178
+ *
179
+ * const transport = new HttpTransport(); // or `WebSocketTransport`
180
+ * const data = await l3Orders(
181
+ * { transport },
182
+ * { coin: "BTC", pxMin: "35000", pxMax: "37000" },
183
+ * );
184
+ * ```
185
+ */
186
+ export function l3Orders(
187
+ config: InfoRequestConfig,
188
+ params: DeepImmutable<L3OrdersParameters>,
189
+ signal?: AbortSignal,
190
+ ): Promise<L3OrdersResponse> {
191
+ const parsedParams = parser(L3OrdersParametersSchema)(params);
192
+ const pxMin = "px" in parsedParams ? parsedParams.px : parsedParams.pxMin;
193
+ const pxMax = "px" in parsedParams ? parsedParams.px : parsedParams.pxMax;
194
+ const request = parser(L3OrdersRequest)({
195
+ type: "l3Orders",
196
+ coin: parsedParams.coin,
197
+ pxMin,
198
+ pxMax,
199
+ });
200
+ return config.transport.request("info", request, signal);
201
+ }
@@ -99,7 +99,7 @@ export const L4OrderSchema = /* @__PURE__ */ (() => {
99
99
  })();
100
100
 
101
101
  /**
102
- * Request L4 orders at a specific price level.
102
+ * Request L4 orders within a price range.
103
103
  */
104
104
  export const L4OrdersRequest = /* @__PURE__ */ (() => {
105
105
  return v.pipe(
@@ -114,13 +114,18 @@ export const L4OrdersRequest = /* @__PURE__ */ (() => {
114
114
  v.string(),
115
115
  v.description("Asset symbol (e.g., ETH)."),
116
116
  ),
117
- /** Price level to query orders at. */
118
- px: v.pipe(
117
+ /** Minimum price (inclusive). */
118
+ pxMin: v.pipe(
119
+ UnsignedDecimal,
120
+ v.description("Minimum price (inclusive)."),
121
+ ),
122
+ /** Maximum price (inclusive). */
123
+ pxMax: v.pipe(
119
124
  UnsignedDecimal,
120
- v.description("Price level to query orders at."),
125
+ v.description("Maximum price (inclusive)."),
121
126
  ),
122
127
  }),
123
- v.description("Request L4 orders at a specific price level."),
128
+ v.description("Request L4 orders within a price range."),
124
129
  );
125
130
  })();
126
131
  export type L4OrdersRequest = v.InferOutput<typeof L4OrdersRequest>;
@@ -159,14 +164,47 @@ export type L4OrdersResponse = v.InferOutput<typeof L4OrdersResponse>;
159
164
  import type { InfoRequestConfig } from "./_types.js";
160
165
 
161
166
  /** Request parameters for the {@linkcode l4Orders} function. */
162
- export type L4OrdersParameters = Omit<v.InferInput<typeof L4OrdersRequest>, "type">;
167
+ export const L4OrdersParametersSchema = /* @__PURE__ */ (() => {
168
+ return v.union([
169
+ v.object({
170
+ /** Asset symbol (e.g., ETH). */
171
+ coin: v.pipe(
172
+ v.string(),
173
+ v.description("Asset symbol (e.g., ETH)."),
174
+ ),
175
+ /** Price level to query orders at. (Deprecated; use `pxMin`/`pxMax`.) */
176
+ px: v.pipe(
177
+ UnsignedDecimal,
178
+ v.description("Price level to query orders at. (Deprecated; use `pxMin`/`pxMax`.)"),
179
+ ),
180
+ }),
181
+ v.object({
182
+ /** Asset symbol (e.g., ETH). */
183
+ coin: v.pipe(
184
+ v.string(),
185
+ v.description("Asset symbol (e.g., ETH)."),
186
+ ),
187
+ /** Minimum price (inclusive). */
188
+ pxMin: v.pipe(
189
+ UnsignedDecimal,
190
+ v.description("Minimum price (inclusive)."),
191
+ ),
192
+ /** Maximum price (inclusive). */
193
+ pxMax: v.pipe(
194
+ UnsignedDecimal,
195
+ v.description("Maximum price (inclusive)."),
196
+ ),
197
+ }),
198
+ ]);
199
+ })();
200
+ export type L4OrdersParameters = v.InferInput<typeof L4OrdersParametersSchema>;
163
201
 
164
202
  /**
165
- * Request L4 orders at a specific price level.
203
+ * Request L4 orders within a price range.
166
204
  * @param config - General configuration for Info API requests.
167
205
  * @param params - Parameters specific to the API request.
168
206
  * @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.
207
+ * @returns L4 orders snapshot for a price range.
170
208
  *
171
209
  * @throws {TransportError} When the transport layer throws an error.
172
210
  *
@@ -178,7 +216,7 @@ export type L4OrdersParameters = Omit<v.InferInput<typeof L4OrdersRequest>, "typ
178
216
  * const transport = new HttpTransport(); // or `WebSocketTransport`
179
217
  * const data = await l4Orders(
180
218
  * { transport },
181
- * { coin: "ETH", px: "1000" },
219
+ * { coin: "ETH", pxMin: "900", pxMax: "1100" },
182
220
  * );
183
221
  * ```
184
222
  */
@@ -187,9 +225,14 @@ export function l4Orders(
187
225
  params: DeepImmutable<L4OrdersParameters>,
188
226
  signal?: AbortSignal,
189
227
  ): Promise<L4OrdersResponse> {
228
+ const parsedParams = parser(L4OrdersParametersSchema)(params);
229
+ const pxMin = "px" in parsedParams ? parsedParams.px : parsedParams.pxMin;
230
+ const pxMax = "px" in parsedParams ? parsedParams.px : parsedParams.pxMax;
190
231
  const request = parser(L4OrdersRequest)({
191
232
  type: "l4Orders",
192
- ...params,
233
+ coin: parsedParams.coin,
234
+ pxMin,
235
+ pxMax,
193
236
  });
194
237
  return config.transport.request("info", request, signal);
195
- }
238
+ }
@@ -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 { l3Orders } from "./l3Orders.js";
24
25
  import { l4Orders } from "./l4Orders.js";
25
26
  import { leadingVaults } from "./leadingVaults.js";
26
27
  import { legalCheck } from "./legalCheck.js";
@@ -576,10 +577,10 @@ export class InfoClient<T extends IRequestTransport = IRequestTransport> impleme
576
577
  }
577
578
 
578
579
  /**
579
- * Request L4 orders at a specific price level.
580
+ * Request L3 orders within a price range.
580
581
  * @param params - Parameters specific to the API request.
581
582
  * @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
+ * @returns L3 orders snapshot for a price range.
583
584
  *
584
585
  * @throws {TransportError} When the transport layer throws an error.
585
586
  *
@@ -591,7 +592,32 @@ export class InfoClient<T extends IRequestTransport = IRequestTransport> impleme
591
592
  * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
592
593
  *
593
594
  * const client = new hl.InfoClient({ transport });
594
- * const data = await client.l4Orders({ coin: "ETH", px: "1000" });
595
+ * const data = await client.l3Orders({ coin: "BTC", pxMin: "35000", pxMax: "37000" });
596
+ * ```
597
+ */
598
+ l3Orders(
599
+ ...args: OmitFirst<OverloadedParameters<typeof l3Orders>>
600
+ ): ReturnType<typeof l3Orders> {
601
+ return l3Orders(this, ...args);
602
+ }
603
+
604
+ /**
605
+ * Request L4 orders within a price range.
606
+ * @param params - Parameters specific to the API request.
607
+ * @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).
608
+ * @returns L4 orders snapshot for a price range.
609
+ *
610
+ * @throws {TransportError} When the transport layer throws an error.
611
+ *
612
+ * @see null
613
+ * @example
614
+ * ```ts
615
+ * import * as hl from "@nktkas/hyperliquid";
616
+ *
617
+ * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
618
+ *
619
+ * const client = new hl.InfoClient({ transport });
620
+ * const data = await client.l4Orders({ coin: "ETH", pxMin: "900", pxMax: "1100" });
595
621
  * ```
596
622
  */
597
623
  l4Orders(
@@ -1809,6 +1835,7 @@ export type * from "./gossipRootIps.js";
1809
1835
  export type * from "./historicalOrders.js";
1810
1836
  export type * from "./isVip.js";
1811
1837
  export type * from "./l2Book.js";
1838
+ export type * from "./l3Orders.js";
1812
1839
  export type * from "./l4Orders.js";
1813
1840
  export type * from "./leadingVaults.js";
1814
1841
  export type * from "./legalCheck.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 "./l3Orders.js";
46
47
  export * from "./l4Orders.js";
47
48
  export * from "./leadingVaults.js";
48
49
  export * from "./legalCheck.js";