HTX Spot Private JavaScript SDK example: submitOrder.ts

HTX Spot Private submit order JavaScript example for the Siebly HTX 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/HTX/Spot/Private/submitOrder.ts

What this example covers

  • HTX exchange API JavaScript example.
  • Uses the Siebly HTX SDK package @siebly/htx-api instead of hand-written HTTP request plumbing.
  • Source path: HTX/Spot/Private/submitOrder.ts.
  • Example category: Spot Private.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getAccounts(), submitOrder(), generateNewOrderID(), submitBatchOrders().

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.
  • For private or order-management examples, keep credentials in environment variables or a secret manager. Use read-only keys where possible, and check the execution mode reference before any exchange write path can run.
  • Open the repository source when you need the latest committed version: GitHub source file.
/* 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(); 

Subscribe on Substack

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