Hyperliquid JavaScript SDK example: rest-cancel-open-orders.ts

Hyperliquid REST cancel open orders JavaScript example for the Siebly Hyperliquid SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Hyperliquid/Rest/rest-cancel-open-orders.ts

What this example covers

  • Hyperliquid REST API JavaScript example.
  • Uses the Siebly Hyperliquid SDK package @siebly/hyperliquid-api instead of hand-written HTTP request plumbing.
  • Source path: Hyperliquid/Rest/rest-cancel-open-orders.ts.
  • Imports SDK symbols including RestClient.
  • Calls SDK methods such as getOpenOrders(), cancelOrders().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { RestClient } from '@siebly/hyperliquid-api'; // or// import { RestClient } from '@siebly/hyperliquid-api'; /** * Cancel every open order on the authenticated account. * * Unix: * HYPERLIQUID_PRIVATE_KEY='0xabc' npx tsx examples/Rest/rest-cancel-open-orders.ts */const privateKey = process.env.HYPERLIQUID_PRIVATE_KEY;if (!privateKey) {  throw new Error(    "Missing HYPERLIQUID_PRIVATE_KEY. Unix example: HYPERLIQUID_PRIVATE_KEY='0xabc' npx tsx examples/Rest/rest-cancel-open-orders.ts",  );} const client = new RestClient({  privateKey,  // testnet: true,}); async function main() {  try {    const openOrders = await client.getOpenOrders();    if (openOrders.length === 0) {      console.log('no open orders');      return;    }     for (const openOrder of openOrders) {      console.log(        'cancelling',        openOrder.coin,        openOrder.oid,        openOrder.limitPx,      );      console.log(        await client.cancelOrders({          cancels: [{ a: openOrder.coin, o: openOrder.oid }],        }),      );    }  } catch (e) {    console.error('request failed: ', e);  }} main(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.