• 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

94.74
/src/api/exchange/_methods/modify.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 { ErrorResponse, SignatureSchema, SuccessResponse } from "./_base/commonSchemas.ts";
388✔
9

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

84
/**
85
 * Successful response without specific data or error response.
86
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
87
 */
88
export const ModifyResponse = /* @__PURE__ */ (() => {
388✔
89
  return v.union([SuccessResponse, ErrorResponse]);
2,632✔
90
})();
388✔
91
export type ModifyResponse = v.InferOutput<typeof ModifyResponse>;
92

93
// ============================================================
94
// Execution Logic
95
// ============================================================
96

97
import { type ExchangeConfig, executeL1Action, type ExtractRequestOptions } from "./_base/execute.ts";
388✔
98
import type { ExcludeErrorResponse } from "./_base/errors.ts";
99

100
/** Schema for user-provided action parameters (excludes system fields). */
101
const ModifyParameters = /* @__PURE__ */ (() => {
388✔
102
  return v.omit(
658✔
103
    v.object(ModifyRequest.entries.action.entries),
658✔
104
    ["type"],
1,974✔
105
  );
106
})();
388✔
107
/** Action parameters for the {@linkcode modify} function. */
108
export type ModifyParameters = v.InferInput<typeof ModifyParameters>;
109

110
/** Request options for the {@linkcode modify} function. */
111
export type ModifyOptions = ExtractRequestOptions<v.InferInput<typeof ModifyRequest>>;
112

113
/** Successful variant of {@linkcode ModifyResponse} without errors. */
114
export type ModifySuccessResponse = ExcludeErrorResponse<ModifyResponse>;
115

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