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

nktkas / hyperliquid / 19405103680

16 Nov 2025 11:46AM UTC coverage: 94.726% (-0.6%) from 95.329%
19405103680

push

github

nktkas
test(info): adapt command execution for Deno and Node.js environments

368 of 581 branches covered (63.34%)

Branch coverage included in aggregate %.

11667 of 12124 relevant lines covered (96.23%)

951.31 hits per line

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

87.32
/src/api/exchange/batchModify.ts
1
import * as v from "valibot";
353✔
2
import { Address, type DeepImmutable, Hex, parser, UnsignedInteger } from "../_base.ts";
353✔
3
import {
353✔
4
  type ExchangeRequestConfig,
5
  executeL1Action,
353✔
6
  type ExtractRequestAction,
7
  type ExtractRequestOptions,
8
  type MultiSignRequestConfig,
9
  Signature,
353✔
10
} from "./_base/mod.ts";
353✔
11

12
import { PlaceOrderParamsSchema } from "../_common_schemas.ts";
353✔
13

14
// -------------------- Schemas --------------------
15

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

76
import { OrderSuccessResponse } from "./order.ts";
353✔
77
export { OrderSuccessResponse };
353✔
78

79
// -------------------- Function --------------------
80

81
/** Action parameters for the {@linkcode batchModify} function. */
82
export type BatchModifyParameters = ExtractRequestAction<v.InferInput<typeof BatchModifyRequest>>;
83
/** Request options for the {@linkcode batchModify} function. */
84
export type BatchModifyOptions = ExtractRequestOptions<v.InferInput<typeof BatchModifyRequest>>;
85

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