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

nktkas / hyperliquid / 21729335997

05 Feb 2026 09:33PM UTC coverage: 92.652% (-2.8%) from 95.464%
21729335997

push

github

nktkas
test: weaken coverage testing of schemas

613 of 806 branches covered (76.05%)

Branch coverage included in aggregate %.

9210 of 9796 relevant lines covered (94.02%)

883.4 hits per line

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

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

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

7
import { Address, Cloid, UnsignedDecimal, UnsignedInteger } from "../../_schemas.ts";
388✔
8
import { SignatureSchema } from "./_base/commonSchemas.ts";
388✔
9
import { OrderResponse } from "./order.ts";
388✔
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__ */ (() => {
388✔
16
  return v.object({
658✔
17
    /** Action to perform. */
18
    action: v.object({
658✔
19
      /** Type of action. */
20
      type: v.literal("batchModify"),
658✔
21
      /** Order modifications. */
22
      modifies: v.array(
658✔
23
        v.object({
658✔
24
          /** Order ID or Client Order ID. */
25
          oid: v.union([UnsignedInteger, Cloid]),
2,632✔
26
          /** New order parameters. */
27
          order: v.object({
658✔
28
            /** Asset ID. */
29
            a: UnsignedInteger,
658✔
30
            /** Position side (`true` for long, `false` for short). */
31
            b: v.boolean(),
658✔
32
            /** Price. */
33
            p: v.pipe(
658✔
34
              UnsignedDecimal,
658✔
35
              v.check((input) => Number(input) > 0, "Value must be greater than zero."),
658✔
36
            ),
37
            /** Size (in base currency units). */
38
            s: UnsignedDecimal,
658✔
39
            /** Is reduce-only? */
40
            r: v.boolean(),
658✔
41
            /** Order type (`limit` for limit orders, `trigger` for stop-loss/take-profit orders). */
42
            t: v.union([
658✔
43
              v.object({
658✔
44
                /** Limit order parameters. */
45
                limit: v.object({
658✔
46
                  /**
47
                   * Time-in-force.
48
                   * - `"Gtc"`: Remains active until filled or canceled.
49
                   * - `"Ioc"`: Fills immediately or cancels any unfilled portion.
50
                   * - `"Alo"`: Adds liquidity only.
51
                   * - `"FrontendMarket"`: Similar to Ioc, used in Hyperliquid UI.
52
                   * - `"LiquidationMarket"`: Similar to Ioc, used in Hyperliquid UI.
53
                   */
54
                  tif: v.picklist(["Gtc", "Ioc", "Alo", "FrontendMarket", "LiquidationMarket"]),
4,606✔
55
                }),
658✔
56
              }),
658✔
57
              v.object({
658✔
58
                /** Trigger order parameters. */
59
                trigger: v.object({
658✔
60
                  /** Is market order? */
61
                  isMarket: v.boolean(),
658✔
62
                  /** Trigger price. */
63
                  triggerPx: v.pipe(
×
64
                    UnsignedDecimal,
×
65
                    v.check((input) => Number(input) > 0, "Value must be greater than zero."),
×
66
                  ),
67
                  /** Indicates whether it is take profit or stop loss. */
68
                  tpsl: v.picklist(["tp", "sl"]),
2,632✔
69
                }),
658✔
70
              }),
658✔
71
            ]),
658✔
72
            /** Client Order ID. */
73
            c: v.optional(Cloid),
658✔
74
          }),
658✔
75
        }),
658✔
76
      ),
77
    }),
658✔
78
    /** Nonce (timestamp in ms) used to prevent replay attacks. */
79
    nonce: UnsignedInteger,
658✔
80
    /** ECDSA signature components. */
81
    signature: SignatureSchema,
658✔
82
    /** Vault address (for vault trading). */
83
    vaultAddress: v.optional(Address),
658✔
84
    /** Expiration time of the action. */
85
    expiresAfter: v.optional(UnsignedInteger),
658✔
86
  });
658✔
87
})();
388✔
88
export type BatchModifyRequest = v.InferOutput<typeof BatchModifyRequest>;
89

90
/**
91
 * Response for order batch modifications.
92
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
93
 */
94
export const BatchModifyResponse = /* @__PURE__ */ (() => {
388✔
95
  return OrderResponse;
658✔
96
})();
388✔
97
export type BatchModifyResponse = OrderResponse;
98

99
// ============================================================
100
// Execution Logic
101
// ============================================================
102

103
import { type ExchangeConfig, executeL1Action, type ExtractRequestOptions } from "./_base/execute.ts";
388✔
104
import type { ExcludeErrorResponse } from "./_base/errors.ts";
105

106
/** Schema for user-provided action parameters (excludes system fields). */
107
const BatchModifyParameters = /* @__PURE__ */ (() => {
388✔
108
  return v.omit(
658✔
109
    v.object(BatchModifyRequest.entries.action.entries),
658✔
110
    ["type"],
1,974✔
111
  );
112
})();
388✔
113
/** Action parameters for the {@linkcode batchModify} function. */
114
export type BatchModifyParameters = v.InferInput<typeof BatchModifyParameters>;
115

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

119
/** Successful variant of {@linkcode BatchModifyResponse} without errors. */
120
export type BatchModifySuccessResponse = ExcludeErrorResponse<BatchModifyResponse>;
121

122
/**
123
 * Modify multiple orders.
124
 *
125
 * @param config - General configuration for Exchange API requests.
126
 * @param params - Parameters specific to the API request.
127
 * @param opts - Request execution options.
128
 *
129
 * @returns Successful variant of {@link OrderResponse} without error statuses.
130
 *
131
 * @throws {ValiError} When the request parameters fail validation (before sending).
132
 * @throws {TransportError} When the transport layer throws an error.
133
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
134
 *
135
 * @example
136
 * ```ts
137
 * import { HttpTransport } from "@nktkas/hyperliquid";
138
 * import { batchModify } from "@nktkas/hyperliquid/api/exchange";
139
 * import { privateKeyToAccount } from "npm:viem/accounts";
140
 *
141
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
142
 * const transport = new HttpTransport(); // or `WebSocketTransport`
143
 *
144
 * const data = await batchModify(
145
 *   { transport, wallet },
146
 *   {
147
 *     modifies: [
148
 *       {
149
 *         oid: 123,
150
 *         order: {
151
 *           a: 0,
152
 *           b: true,
153
 *           p: "31000",
154
 *           s: "0.2",
155
 *           r: false,
156
 *           t: { limit: { tif: "Gtc" } },
157
 *         },
158
 *       },
159
 *     ],
160
 *   },
161
 * );
162
 * ```
163
 *
164
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
165
 */
166
export function batchModify(
388✔
167
  config: ExchangeConfig,
388✔
168
  params: BatchModifyParameters,
388✔
169
  opts?: BatchModifyOptions,
388✔
170
): Promise<BatchModifySuccessResponse> {
171
  const action = v.parse(BatchModifyParameters, params);
397✔
172
  return executeL1Action(config, { type: "batchModify", ...action }, opts);
1,588✔
173
}
397✔
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

© 2026 Coveralls, Inc