• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nktkas / hyperliquid / 20260168111

16 Dec 2025 07:33AM UTC coverage: 95.34% (-1.3%) from 96.688%
20260168111

push

github

nktkas
docs: improve code documentation

661 of 881 branches covered (75.03%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

151 existing lines in 17 files now uncovered.

12843 of 13283 relevant lines covered (96.69%)

1103.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.49
/src/api/exchange/_methods/batchModify.ts
1
import * as v from "@valibot/valibot";
364✔
2

3
// ============================================================
4
// API Schemas
5
// ============================================================
6

7
import { Address, Cloid, UnsignedDecimal, UnsignedInteger } from "../../_schemas.ts";
364✔
8
import { SignatureSchema } from "./_base/commonSchemas.ts";
364✔
9
import { OrderResponse } from "./order.ts";
364✔
10

11
/**
12
 * Modify multiple orders.
13
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
14
 */
15
export const BatchModifyRequest = /* @__PURE__ */ (() => {
364✔
16
  return v.pipe(
618✔
17
    v.object({
618✔
18
      /** Action to perform. */
19
      action: v.pipe(
618✔
20
        v.object({
618✔
21
          /** Type of action. */
22
          type: v.pipe(
618✔
23
            v.literal("batchModify"),
618✔
24
            v.description("Type of action."),
618✔
25
          ),
26
          /** Order modifications. */
27
          modifies: v.pipe(
618✔
28
            v.array(
618✔
29
              v.object({
618✔
30
                /** Order ID or Client Order ID. */
31
                oid: v.pipe(
618✔
32
                  v.union([UnsignedInteger, Cloid]),
2,472✔
33
                  v.description("Order ID or Client Order ID."),
618✔
34
                ),
35
                /** New order parameters. */
36
                order: v.pipe(
618✔
37
                  v.object({
618✔
38
                    /** Asset ID. */
39
                    a: v.pipe(
618✔
40
                      UnsignedInteger,
618✔
41
                      v.description("Asset ID."),
618✔
42
                    ),
43
                    /** Position side (`true` for long, `false` for short). */
44
                    b: v.pipe(
618✔
45
                      v.boolean(),
618✔
46
                      v.description("Position side (`true` for long, `false` for short)."),
618✔
47
                    ),
48
                    /** Price. */
49
                    p: v.pipe(
618✔
50
                      UnsignedDecimal,
618✔
51
                      v.check((input) => Number(input) > 0, "Value must be greater than zero."),
618✔
52
                      v.description("Price."),
618✔
53
                    ),
54
                    /** Size (in base currency units). */
55
                    s: v.pipe(
618✔
56
                      UnsignedDecimal,
618✔
57
                      v.description("Size (in base currency units)."),
618✔
58
                    ),
59
                    /** Is reduce-only? */
60
                    r: v.pipe(
618✔
61
                      v.boolean(),
618✔
62
                      v.description("Is reduce-only?"),
618✔
63
                    ),
64
                    /** Order type (`limit` for limit orders, `trigger` for stop-loss/take-profit orders). */
65
                    t: v.pipe(
618✔
66
                      v.union([
618✔
67
                        v.object({
618✔
68
                          /** Limit order parameters. */
69
                          limit: v.pipe(
618✔
70
                            v.object({
618✔
71
                              /**
72
                               * Time-in-force.
73
                               * - `"Gtc"`: Remains active until filled or canceled.
74
                               * - `"Ioc"`: Fills immediately or cancels any unfilled portion.
75
                               * - `"Alo"`: Adds liquidity only.
76
                               * - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.
77
                               * - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.
78
                               */
79
                              tif: v.pipe(
618✔
80
                                v.picklist(["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"]),
4,326✔
81
                                v.description(
618✔
82
                                  "Time-in-force." +
618✔
83
                                    '\n- `"Gtc"`: Remains active until filled or canceled.' +
618✔
84
                                    '\n- `"Ioc"`: Fills immediately or cancels any unfilled portion.' +
618✔
85
                                    '\n- `"Alo"`: Adds liquidity only.' +
618✔
86
                                    '\n- `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.' +
618✔
87
                                    '\n- `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.',
618✔
88
                                ),
89
                              ),
90
                            }),
618✔
91
                            v.description("Limit order parameters."),
618✔
92
                          ),
93
                        }),
618✔
94
                        v.object({
618✔
95
                          /** Trigger order parameters. */
96
                          trigger: v.pipe(
618✔
97
                            v.object({
618✔
98
                              /** Is market order? */
99
                              isMarket: v.pipe(
618✔
100
                                v.boolean(),
618✔
101
                                v.description("Is market order?"),
618✔
102
                              ),
103
                              /** Trigger price. */
UNCOV
104
                              triggerPx: v.pipe(
×
UNCOV
105
                                UnsignedDecimal,
×
UNCOV
106
                                v.check((input) => Number(input) > 0, "Value must be greater than zero."),
×
UNCOV
107
                                v.description("Trigger price."),
×
108
                              ),
109
                              /** Indicates whether it is take profit or stop loss. */
110
                              tpsl: v.pipe(
618✔
111
                                v.picklist(["tp", "sl"]),
2,472✔
112
                                v.description("Indicates whether it is take profit or stop loss."),
618✔
113
                              ),
114
                            }),
618✔
115
                            v.description("Trigger order parameters."),
618✔
116
                          ),
117
                        }),
618✔
118
                      ]),
618✔
119
                      v.description(
618✔
120
                        "Order type (`limit` for limit orders, `trigger` for stop-loss/take-profit orders).",
618✔
121
                      ),
122
                    ),
123
                    /** Client Order ID. */
124
                    c: v.pipe(
618✔
125
                      v.optional(Cloid),
618✔
126
                      v.description("Client Order ID."),
618✔
127
                    ),
128
                  }),
618✔
129
                  v.description("New order parameters."),
618✔
130
                ),
131
              }),
618✔
132
            ),
133
            v.description("Order modifications."),
618✔
134
          ),
135
        }),
618✔
136
        v.description("Action to perform."),
618✔
137
      ),
138
      /** Nonce (timestamp in ms) used to prevent replay attacks. */
139
      nonce: v.pipe(
618✔
140
        UnsignedInteger,
618✔
141
        v.description("Nonce (timestamp in ms) used to prevent replay attacks."),
618✔
142
      ),
143
      /** ECDSA signature components. */
144
      signature: v.pipe(
618✔
145
        SignatureSchema,
618✔
146
        v.description("ECDSA signature components."),
618✔
147
      ),
148
      /** Vault address (for vault trading). */
149
      vaultAddress: v.pipe(
618✔
150
        v.optional(Address),
618✔
151
        v.description("Vault address (for vault trading)."),
618✔
152
      ),
153
      /** Expiration time of the action. */
154
      expiresAfter: v.pipe(
618✔
155
        v.optional(UnsignedInteger),
618✔
156
        v.description("Expiration time of the action."),
618✔
157
      ),
158
    }),
618✔
159
    v.description("Modify multiple orders."),
618✔
160
  );
161
})();
364✔
162
export type BatchModifyRequest = v.InferOutput<typeof BatchModifyRequest>;
163

164
/**
165
 * Response for order batch modifications.
166
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
167
 */
168
export const BatchModifyResponse = /* @__PURE__ */ (() => {
364✔
169
  return v.pipe(
618✔
170
    OrderResponse,
618✔
171
    v.description("Response for order batch modifications."),
618✔
172
  );
173
})();
364✔
174
export type BatchModifyResponse = OrderResponse;
175

176
// ============================================================
177
// Execution Logic
178
// ============================================================
179

180
import { type ExchangeConfig, executeL1Action, type ExtractRequestOptions } from "./_base/execute.ts";
364✔
181
import type { ExcludeErrorResponse } from "./_base/errors.ts";
182

183
/** Schema for user-provided action parameters (excludes system fields). */
184
const BatchModifyParameters = /* @__PURE__ */ (() => {
364✔
185
  return v.omit(
618✔
186
    v.object(BatchModifyRequest.entries.action.entries),
618✔
187
    ["type"],
1,854✔
188
  );
189
})();
364✔
190
/** Action parameters for the {@linkcode batchModify} function. */
191
export type BatchModifyParameters = v.InferInput<typeof BatchModifyParameters>;
192

193
/** Request options for the {@linkcode batchModify} function. */
194
export type BatchModifyOptions = ExtractRequestOptions<v.InferInput<typeof BatchModifyRequest>>;
195

196
/** Successful variant of {@linkcode BatchModifyResponse} without errors. */
197
export type BatchModifySuccessResponse = ExcludeErrorResponse<BatchModifyResponse>;
198

199
/**
200
 * Modify multiple orders.
201
 *
202
 * @param config - General configuration for Exchange API requests.
203
 * @param params - Parameters specific to the API request.
204
 * @param opts - Request execution options.
205
 *
206
 * @returns Successful variant of {@link OrderResponse} without error statuses.
207
 *
208
 * @throws {ValiError} When the request parameters fail validation (before sending).
209
 * @throws {TransportError} When the transport layer throws an error.
210
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
211
 *
212
 * @example
213
 * ```ts
214
 * import { HttpTransport } from "@nktkas/hyperliquid";
215
 * import { batchModify } from "@nktkas/hyperliquid/api/exchange";
216
 * import { privateKeyToAccount } from "npm:viem/accounts";
217
 *
218
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
219
 * const transport = new HttpTransport(); // or `WebSocketTransport`
220
 *
221
 * const data = await batchModify(
222
 *   { transport, wallet },
223
 *   {
224
 *     modifies: [
225
 *       {
226
 *         oid: 123,
227
 *         order: {
228
 *           a: 0,
229
 *           b: true,
230
 *           p: "31000",
231
 *           s: "0.2",
232
 *           r: false,
233
 *           t: { limit: { tif: "Gtc" } },
234
 *         },
235
 *       },
236
 *     ],
237
 *   },
238
 * );
239
 * ```
240
 *
241
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
242
 */
243
export function batchModify(
364✔
244
  config: ExchangeConfig,
364✔
245
  params: BatchModifyParameters,
364✔
246
  opts?: BatchModifyOptions,
364✔
247
): Promise<BatchModifySuccessResponse> {
248
  const action = v.parse(BatchModifyParameters, params);
373✔
249
  return executeL1Action(config, { type: "batchModify", ...action }, opts);
1,492✔
250
}
373✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc