@nktkas/hyperliquid
Version:
Hyperliquid API SDK for all major JS runtimes, written in TypeScript.
59 lines • 3.19 kB
JavaScript
import * as v from "valibot";
// ============================================================
// API Schemas
// ============================================================
import { Address, UnsignedInteger } from "../../_schemas.js";
import { ErrorResponse, Nonce, Signature, SuccessResponse } from "./_base/schemas.js";
/**
* Schedule a cancel-all operation at a future time.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch
*/
export const ScheduleCancelRequest = /* @__PURE__ */ (() => {
return v.pipe(v.object({
/** Action to perform. */
action: v.pipe(v.object({
/** Type of action. */
type: v.pipe(v.literal("scheduleCancel"), v.description("Type of action.")),
/**
* Scheduled time (in ms since epoch).
* Must be at least 5 seconds in the future.
*
* If not specified, will cause all scheduled cancel operations to be deleted.
*/
time: v.pipe(v.optional(UnsignedInteger), v.description("Scheduled time (in ms since epoch)." +
"\nMust be at least 5 seconds in the future." +
"\n\nIf not specified, will cause all scheduled cancel operations to be deleted.")),
}), 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("Schedule a cancel-all operation at a future time."));
})();
/**
* Successful response without specific data or error response.
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch
*/
export const ScheduleCancelResponse = /* @__PURE__ */ (() => {
return v.pipe(v.union([SuccessResponse, ErrorResponse]), v.description("Successful response without specific data or error response."));
})();
// ============================================================
// Execution Logic
// ============================================================
import { executeL1Action } from "./_base/execute.js";
/** Schema for user-provided action parameters (excludes system fields). */
const ScheduleCancelParameters = /* @__PURE__ */ (() => {
return v.omit(v.object(ScheduleCancelRequest.entries.action.entries), ["type"]);
})();
export function scheduleCancel(config, paramsOrOpts, maybeOpts) {
const isFirstArgParams = paramsOrOpts && "time" in paramsOrOpts;
const params = isFirstArgParams ? paramsOrOpts : {};
const opts = isFirstArgParams ? maybeOpts : paramsOrOpts;
const action = v.parse(ScheduleCancelParameters, params);
return executeL1Action(config, { type: "scheduleCancel", ...action }, opts);
}
//# sourceMappingURL=scheduleCancel.js.map