---
title: "Hyperliquid REST Schedule Cancel Example | Siebly"
description: "Hyperliquid REST schedule cancel JavaScript example for the Siebly Hyperliquid SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs."
canonical: "https://siebly.io/examples/Hyperliquid/Rest/rest-schedule-cancel"
robots: "index,follow"
---

# Hyperliquid REST Schedule Cancel Example

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

**Path:** [Home](/) / [Examples](/examples) / [Hyperliquid](/examples/Hyperliquid) / [Rest](/examples/Hyperliquid/Rest) / [rest-schedule-cancel.ts](/examples/Hyperliquid/Rest/rest-schedule-cancel)

[View source on GitHub](https://github.com/sieblyio/hyperliquid-api/blob/main/examples/Rest/rest-schedule-cancel.ts)

[Open the Hyperliquid JavaScript SDK guide](/sdk/hyperliquid/javascript)

## rest-schedule-cancel.ts

```typescript
import {
  type ExchangeResponse,
  type OrderResponseData,
  RestClient,
} from '@siebly/hyperliquid-api';

// or
// import { RestClient } from '@siebly/hyperliquid-api';

/**
 * Dead-man's switch: place a resting limit, then schedule cancel-all after 10s.
 * Hyperliquid only enables this after $1M traded volume; the example still
 * places and cancels the limit so the order path is exercised either way.
 *
 * Unix:
 * HYPERLIQUID_PRIVATE_KEY='0xabc' npx tsx examples/Rest/rest-schedule-cancel.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-schedule-cancel.ts",
  );
}

const client = new RestClient({
  privateKey,
  // testnet: true,
});

function firstRestingOid(
  result: ExchangeResponse<OrderResponseData>,
): number | undefined {
  if (result.status !== 'ok') {
    return undefined;
  }
  const status = result.response.data?.statuses[0];
  return status && 'resting' in status ? status.resting.oid : undefined;
}

async function main() {
  try {
    const result = await client.submitLimitOrder({
      price: '1100',
      side: 'buy',
      size: '0.01',
      symbol: 'ETH',
    });
    console.log('limit order:', JSON.stringify(result, null, 2));

    const oid = firstRestingOid(result);
    if (oid !== undefined) {
      console.log('status:', await client.getOrderStatus({ oid }));
    }

    try {
      console.log(
        'schedule cancel-all:',
        await client.setCancelAllAfter({ time: Date.now() + 10_000 }),
      );
    } catch (e) {
      console.log(
        'schedule cancel-all skipped:',
        e instanceof Error ? e.message : e,
      );
    }

    if (oid !== undefined) {
      console.log(
        'cancel resting order:',
        await client.cancelOrders({
          cancels: [{ a: 'ETH', o: oid }],
        }),
      );
    }
  } catch (e) {
    console.error('request failed: ', e);
  }
}

main();
```
