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

nktkas / hyperliquid / 19514753888

19 Nov 2025 08:02PM UTC coverage: 94.811% (+0.1%) from 94.685%
19514753888

push

github

nktkas
ci: remove environment for test job

364 of 583 branches covered (62.44%)

Branch coverage included in aggregate %.

12208 of 12677 relevant lines covered (96.3%)

964.38 hits per line

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

87.5
/src/api/exchange/batchModify.ts
1
import * as v from "valibot";
357✔
2

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

7
import { Address, Hex, UnsignedInteger } from "../_base.ts";
357✔
8
import { Signature } from "./_base/mod.ts";
357✔
9
import { PlaceOrderParamsSchema } from "../_common_schemas.ts";
357✔
10
import { OrderResponse } from "./order.ts";
357✔
11

12
/**
13
 * Modify multiple orders.
14
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
15
 */
16
export const BatchModifyRequest = /* @__PURE__ */ (() => {
357✔
17
  return v.pipe(
605✔
18
    v.object({
605✔
19
      /** Action to perform. */
20
      action: v.pipe(
605✔
21
        v.object({
605✔
22
          /** Type of action. */
23
          type: v.pipe(
605✔
24
            v.literal("batchModify"),
605✔
25
            v.description("Type of action."),
605✔
26
          ),
27
          /** Order modifications. */
28
          modifies: v.pipe(
605✔
29
            v.array(v.object({
605✔
30
              /** Order ID or Client Order ID. */
31
              oid: v.pipe(
605✔
32
                v.union([
605✔
33
                  UnsignedInteger,
605✔
34
                  v.pipe(Hex, v.length(34)),
605✔
35
                ]),
605✔
36
                v.description("Order ID or Client Order ID."),
605✔
37
              ),
38
              /** New order parameters. */
39
              order: PlaceOrderParamsSchema,
605✔
40
            })),
605✔
41
            v.description("Order modifications."),
605✔
42
          ),
43
        }),
605✔
44
        v.description("Action to perform."),
605✔
45
      ),
46
      /** Unique request identifier (current timestamp in ms). */
47
      nonce: v.pipe(
605✔
48
        UnsignedInteger,
605✔
49
        v.description("Unique request identifier (current timestamp in ms)."),
605✔
50
      ),
51
      /** Cryptographic signature. */
52
      signature: v.pipe(
605✔
53
        Signature,
605✔
54
        v.description("Cryptographic signature."),
605✔
55
      ),
56
      /** Vault address (for vault trading). */
57
      vaultAddress: v.pipe(
605✔
58
        v.optional(Address),
605✔
59
        v.description("Vault address (for vault trading)."),
605✔
60
      ),
61
      /** Expiration time of the action. */
62
      expiresAfter: v.pipe(
605✔
63
        v.optional(UnsignedInteger),
605✔
64
        v.description("Expiration time of the action."),
605✔
65
      ),
66
    }),
605✔
67
    v.description("Modify multiple orders."),
605✔
68
  );
69
})();
357✔
70
export type BatchModifyRequest = v.InferOutput<typeof BatchModifyRequest>;
71

72
/**
73
 * Response for order placement and batch modifications.
74
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
75
 */
76
export const BatchModifyResponse = OrderResponse;
357✔
77
export type BatchModifyResponse = OrderResponse;
78

79
// ============================================================
80
// Execution Logic
81
// ============================================================
82

83
import { type DeepImmutable, parser } from "../_base.ts";
357✔
84
import {
357✔
85
  type ExchangeRequestConfig,
86
  type ExcludeErrorResponse,
87
  executeL1Action,
357✔
88
  type ExtractRequestAction,
89
  type ExtractRequestOptions,
90
  type MultiSignRequestConfig,
91
} from "./_base/mod.ts";
357✔
92

93
/** Action parameters for the {@linkcode batchModify} function. */
94
export type BatchModifyParameters = ExtractRequestAction<v.InferInput<typeof BatchModifyRequest>>;
95

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

99
/** Successful variant of {@linkcode BatchModifyResponse} without errors. */
100
export type BatchModifySuccessResponse = ExcludeErrorResponse<BatchModifyResponse>;
101

102
/**
103
 * Modify multiple orders.
104
 * @param config - General configuration for Exchange API requests.
105
 * @param params - Parameters specific to the API request.
106
 * @param opts - Request execution options.
107
 * @returns Successful variant of {@link OrderResponse} without error statuses.
108
 *
109
 * @throws {ApiRequestError} When the API returns an unsuccessful response.
110
 * @throws {TransportError} When the transport layer throws an error.
111
 *
112
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
113
 * @example
114
 * ```ts
115
 * import { HttpTransport } from "@nktkas/hyperliquid";
116
 * import { batchModify } from "@nktkas/hyperliquid/api/exchange";
117
 * import { privateKeyToAccount } from "viem/accounts";
118
 *
119
 * const wallet = privateKeyToAccount("0x..."); // viem or ethers
120
 * const transport = new HttpTransport(); // or `WebSocketTransport`
121
 *
122
 * const data = await batchModify(
123
 *   { transport, wallet },
124
 *   {
125
 *     modifies: [
126
 *       {
127
 *         oid: 123,
128
 *         order: {
129
 *           a: 0,
130
 *           b: true,
131
 *           p: "31000",
132
 *           s: "0.2",
133
 *           r: false,
134
 *           t: { limit: { tif: "Gtc" } },
135
 *         },
136
 *       },
137
 *     ],
138
 *   },
139
 * );
140
 * ```
141
 */
142
export async function batchModify(
357✔
143
  config: ExchangeRequestConfig | MultiSignRequestConfig,
357✔
144
  params: DeepImmutable<BatchModifyParameters>,
357✔
145
  opts?: BatchModifyOptions,
357✔
146
): Promise<BatchModifySuccessResponse> {
147
  const request = parser(BatchModifyRequest)({
366✔
148
    action: {
366✔
149
      type: "batchModify",
366✔
150
      ...params,
366✔
151
    },
366✔
152
    nonce: 0, // Placeholder; actual nonce generated in `executeL1Action`
366✔
153
    signature: { // Placeholder; actual signature generated in `executeL1Action`
366✔
154
      r: "0x0000000000000000000000000000000000000000000000000000000000000000",
366✔
155
      s: "0x0000000000000000000000000000000000000000000000000000000000000000",
366✔
156
      v: 27,
366✔
157
    },
366✔
158
    vaultAddress: opts?.vaultAddress ?? config.defaultVaultAddress,
×
159
    expiresAfter: typeof config.defaultExpiresAfter === "number"
×
160
      ? config.defaultExpiresAfter
×
161
      : await config.defaultExpiresAfter?.(),
×
162
  });
366✔
163
  return await executeL1Action(config, request, opts?.signal);
×
164
}
366✔
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