• 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.32
/src/api/exchange/modify.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 { ErrorResponse, Signature, SuccessResponse } from "./_base/mod.ts";
357✔
9
import { PlaceOrderParamsSchema } from "../_common_schemas.ts";
357✔
10

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

65
/**
66
 * Successful response without specific data or error response.
67
 * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
68
 */
69
export const ModifyResponse = /* @__PURE__ */ (() => {
357✔
70
  return v.pipe(
605✔
71
    v.union([SuccessResponse, ErrorResponse]),
2,420✔
72
    v.description("Successful response without specific data or error response."),
605✔
73
  );
74
})();
357✔
75
export type ModifyResponse = v.InferOutput<typeof ModifyResponse>;
76

77
// ============================================================
78
// Execution Logic
79
// ============================================================
80

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

91
/** Action parameters for the {@linkcode modify} function. */
92
export type ModifyParameters = ExtractRequestAction<v.InferInput<typeof ModifyRequest>>;
93

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

97
/** Successful variant of {@linkcode ModifyResponse} without errors. */
98
export type ModifySuccessResponse = ExcludeErrorResponse<ModifyResponse>;
99

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