---
title: "Hyperliquid REST Spot Order JavaScript SDK Example | Siebly"
description: "Hyperliquid REST spot order 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-spot-order"
robots: "index,follow"
---

# Hyperliquid REST Spot Order JavaScript SDK Example

Hyperliquid REST spot order 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-spot-order.ts](/examples/Hyperliquid/Rest/rest-spot-order)

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

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

## rest-spot-order.ts

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

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

/**
 * Spot limit order on PURR/USDC. Spot size is always the base asset quantity.
 * Hyperliquid requires a minimum order value of 10 USDC.
 *
 * Unix:
 * HYPERLIQUID_PRIVATE_KEY='0xabc' npx tsx examples/Rest/rest-spot-order.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-spot-order.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 balances = await client.getSpotBalances();
    console.log('spot balances:', balances.balances);

    const purr = await client.submitLimitOrder({
      price: '0.01',
      side: 'buy',
      size: '1100',
      symbol: 'PURR/USDC',
    });
    console.log('PURR/USDC order:', JSON.stringify(purr, null, 2));

    const oid = firstRestingOid(purr);
    if (oid === undefined) {
      console.log('order did not rest; nothing to cancel');
      return;
    }

    console.log('status:', await client.getOrderStatus({ oid }));
    console.log(
      'cancel:',
      await client.cancelOrders({
        cancels: [{ a: 'PURR/USDC', o: oid }],
      }),
    );

    // Numeric spot IDs also work. @107 is the HYPE/USDC alias on mainnet;
    // testnet IDs differ. Prefer the pair name.
    // const other = await client.submitLimitOrder({
    //   price: '12',
    //   side: 'buy',
    //   size: '1',
    //   symbol: '@8',
    // });
  } catch (e) {
    console.error('request failed: ', e);
  }
}

main();
```
