UNPKG

@nktkas/hyperliquid

Version:

Hyperliquid API SDK for all major JS runtimes, written in TypeScript.

89 lines 3.89 kB
import * as v from "valibot"; // ============================================================ // API Schemas // ============================================================ import { Address, Hex, UnsignedInteger } from "../../_schemas.js"; import { Nonce, Signature } from "./_base/schemas.js"; import { CancelResponse } from "./cancel.js"; /** * Cancel order(s) by cloid. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid */ export const CancelByCloidRequest = /* @__PURE__ */ (() => { return v.pipe(v.object({ /** Action to perform. */ action: v.pipe(v.object({ /** Type of action. */ type: v.pipe(v.literal("cancelByCloid"), v.description("Type of action.")), /** Orders to cancel. */ cancels: v.pipe(v.array(v.object({ /** Asset ID. */ asset: v.pipe(UnsignedInteger, v.description("Asset ID.")), /** Client Order ID. */ cloid: v.pipe(v.pipe(Hex, v.length(34)), v.description("Client Order ID.")), })), v.description("Orders to cancel.")), }), v.description("Action to perform.")), /** Nonce (timestamp in ms) used to prevent replay attacks. */ nonce: Nonce, /** ECDSA signature components. */ signature: Signature, /** Vault address (for vault trading). */ vaultAddress: v.pipe(v.optional(Address), v.description("Vault address (for vault trading).")), /** Expiration time of the action. */ expiresAfter: v.pipe(v.optional(UnsignedInteger), v.description("Expiration time of the action.")), }), v.description("Cancel order(s) by cloid.")); })(); /** * Response for order cancellation by cloid. * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid */ export const CancelByCloidResponse = /* @__PURE__ */ (() => { return v.pipe(CancelResponse, v.description("Response for order cancellation by cloid.")); })(); // ============================================================ // Execution Logic // ============================================================ import { executeL1Action } from "./_base/execute.js"; /** Schema for user-provided action parameters (excludes system fields). */ const CancelByCloidParameters = /* @__PURE__ */ (() => { return v.omit(v.object(CancelByCloidRequest.entries.action.entries), ["type"]); })(); /** * Cancel order(s) by cloid. * * @param config - General configuration for Exchange API requests. * @param params - Parameters specific to the API request. * @param opts - Request execution options. * * @returns Successful variant of {@link CancelResponse} without error statuses. * * @throws {ValiError} When the request parameters fail validation (before sending). * @throws {TransportError} When the transport layer throws an error. * @throws {ApiRequestError} When the API returns an unsuccessful response. * * @example * ```ts * import { HttpTransport } from "@nktkas/hyperliquid"; * import { cancelByCloid } from "@nktkas/hyperliquid/api/exchange"; * import { privateKeyToAccount } from "npm:viem/accounts"; * * const wallet = privateKeyToAccount("0x..."); // viem or ethers * const transport = new HttpTransport(); // or `WebSocketTransport` * * const data = await cancelByCloid( * { transport, wallet }, * { * cancels: [ * { asset: 0, cloid: "0x..." }, * ], * }, * ); * ``` * * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid */ export function cancelByCloid(config, params, opts) { const action = v.parse(CancelByCloidParameters, params); return executeL1Action(config, { type: "cancelByCloid", ...action }, opts); } //# sourceMappingURL=cancelByCloid.js.map