@hfunlabs/hyperliquid 0.27.1-hfunlabs.1 → 0.27.1-hfunlabs.2

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.
@@ -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";