---
title: "HTX Spot Private Submit Order Example | Siebly"
description: "HTX Spot Private submit order JavaScript example for the Siebly HTX SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs."
canonical: "https://siebly.io/examples/HTX/Spot/Private/submitOrder"
robots: "index,follow"
---

# HTX Spot Private Submit Order Example

HTX Spot Private submit order JavaScript example for the Siebly HTX SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

**Path:** [Home](/) / [Examples](/examples) / [HTX](/examples/HTX) / [Spot](/examples/HTX/Spot) / [Private](/examples/HTX/Spot/Private) / [submitOrder.ts](/examples/HTX/Spot/Private/submitOrder)

[View source on GitHub](https://github.com/sieblyio/crypto-api-examples/blob/master/examples/HTX/Spot/Private/submitOrder.ts)

[Open the HTX JavaScript SDK guide](/sdk/htx/javascript)

## submitOrder.ts

```typescript
/* eslint-disable @typescript-eslint/no-unused-vars */
import { SpotClient } from '@siebly/htx-api';

// This example shows how to call HTX Spot API endpoints for SUBMITTING ORDERS.

/**
 * HTX API uses API Key and API Secret.
 *
 * API Key Permissions Required: Trade permission (create orders)
 */
/* const client = new SpotClient({
  apiKey: process.env.API_SPOT_KEY || 'insertApiKeyHere',
  apiSecret: process.env.API_SPOT_SECRET || 'insertApiSecretHere',
}); */

const client = new SpotClient({
  apiKey: process.env.API_SPOT_KEY || 'insertApiKeyHere',
  apiSecret: process.env.API_SPOT_SECRET || 'insertApiSecretHere',
});

async function getSpotAccountId(): Promise<string | number | undefined> {
  const accounts = await client.getAccounts();
  return accounts.data?.find((account) => account.type === 'spot')?.id;
}

async function submitMarketOrder() {
  try {
    const accountId = await getSpotAccountId();
    if (!accountId) {
      console.error('No spot account id found');
      return;
    }

    const newOrder = await client.submitOrder({
      'account-id': accountId,
      symbol: 'btcusdt',
      type: 'buy-market',
      amount: '1', // buy-market amount is quote currency value (USDT)
      'client-order-id': client.generateNewOrderID(),
    });
    console.log('Market Order Result: ', newOrder);
  } catch (e) {
    console.error('Submit market order error: ', e);
  }
}

async function submitLimitOrder() {
  try {
    const accountId = await getSpotAccountId();
    if (!accountId) {
      console.error('No spot account id found');
      return;
    }

    const limitOrder = await client.submitOrder({
      'account-id': accountId,
      symbol: 'btcusdt',
      type: 'buy-limit',
      amount: '0.0001',
      price: '10000',
      'client-order-id': client.generateNewOrderID(),
    });
    console.log('Limit Order Result: ', limitOrder);
  } catch (e) {
    console.error('Submit limit order error: ', e);
  }
}

async function submitLimitMakerOrder() {
  try {
    const accountId = await getSpotAccountId();
    if (!accountId) {
      console.error('No spot account id found');
      return;
    }

    const postOnlyOrder = await client.submitOrder({
      'account-id': accountId,
      symbol: 'btcusdt',
      type: 'buy-limit-maker',
      amount: '0.0001',
      price: '10000',
      'client-order-id': client.generateNewOrderID(),
    });
    console.log('Limit Maker Order Result: ', postOnlyOrder);
  } catch (e) {
    console.error('Submit limit maker order error: ', e);
  }
}

async function submitBatchOrders() {
  try {
    const accountId = await getSpotAccountId();
    if (!accountId) {
      console.error('No spot account id found');
      return;
    }

    const batchResult = await client.submitBatchOrders([
      {
        'account-id': accountId,
        symbol: 'btcusdt',
        type: 'buy-limit',
        amount: '0.0001',
        price: '10000',
        'client-order-id': client.generateNewOrderID(),
      },
      {
        'account-id': accountId,
        symbol: 'btcusdt',
        type: 'buy-limit',
        amount: '0.0001',
        price: '10000',
        'client-order-id': client.generateNewOrderID(),
      },
    ]);
    console.log('Batch Order Result: ', JSON.stringify(batchResult, null, 2));
  } catch (e) {
    console.error('Submit batch orders error: ', e);
  }
}

// Uncomment the function you want to test:

// submitMarketOrder();
// submitLimitOrder();
// submitLimitMakerOrder();
// submitBatchOrders();
```
