HTX Derivatives Private JavaScript SDK example: submitOrder.ts

HTX Derivatives 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/Derivatives/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/Derivatives/Private/submitOrder.ts.
  • Example category: Derivatives Private.
  • Imports SDK symbols including FuturesClient.
  • Calls SDK methods such as submitLinearSwapIsolatedOrder(), submitLinearSwapCrossOrder(), submitLinearSwapIsolatedBatchOrders(), submitLinearSwapCrossBatchOrders(), submitMultiAssetOrder(), submitMultiAssetBatchOrders(), submitCoinMDeliveryOrder(), submitCoinMDeliveryBatchOrders(), submitCoinMPerpOrder(), submitCoinMPerpBatchOrders(), submitCoinMPerpLightningCloseOrder().

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 { FuturesClient } from '@siebly/htx-api'; // This example shows how to call HTX Derivatives API endpoints for SUBMITTING ORDERS. const client = new FuturesClient({  apiKey: process.env.API_FUTURES_KEY || '',  apiSecret: process.env.API_FUTURES_SECRET || '',}); const linearSwapContractCode = 'BTC-USDT';const coinMDeliverySymbol = 'BTC';const coinMDeliveryContractType = 'quarter' as const;const coinMPerpContractCode = 'BTC-USD';const leverRate = 1; async function submitLinearSwapIsolatedOrder() {  try {    const res = await client.submitLinearSwapIsolatedOrder({      contract_code: linearSwapContractCode,      direction: 'buy',      offset: 'open',      volume: 1,      lever_rate: leverRate,      order_price_type: 'market',    });    console.log('Linear Swap Isolated Order: ', res);  } catch (e) {    console.error('Submit linear swap isolated order error: ', e);  }} async function submitLinearSwapCrossOrder() {  try {    const res = await client.submitLinearSwapCrossOrder({      contract_code: linearSwapContractCode,      direction: 'buy',      offset: 'open',      volume: 2,      lever_rate: leverRate,      order_price_type: 'market',    });    console.log('Linear Swap Cross Order: ', res);  } catch (e) {    console.error('Submit linear swap cross order error: ', e);  }} async function submitLinearSwapIsolatedBatchOrders() {  try {    const res = await client.submitLinearSwapIsolatedBatchOrders({      orders_data: [        {          contract_code: linearSwapContractCode,          direction: 'buy',          offset: 'open',          volume: 3,          lever_rate: leverRate,          order_price_type: 'market',        },      ],    });    console.log(      'Linear Swap Isolated Batch Orders: ',      JSON.stringify(res, null, 2),    );  } catch (e) {    console.error('Submit linear swap isolated batch orders error: ', e);  }} async function submitLinearSwapCrossBatchOrders() {  try {    const res = await client.submitLinearSwapCrossBatchOrders({      orders_data: [        {          contract_code: linearSwapContractCode,          direction: 'buy',          offset: 'open',          volume: 4,          lever_rate: leverRate,          order_price_type: 'market',        },      ],    });    console.log(      'Linear Swap Cross Batch Orders: ',      JSON.stringify(res, null, 2),    );  } catch (e) {    console.error('Submit linear swap cross batch orders error: ', e);  }} async function submitMultiAssetOrder() {  try {    const res = await client.submitMultiAssetOrder({      contract_code: linearSwapContractCode,      margin_mode: 'cross',      side: 'buy',      type: 'market',      volume: '5',      position_side: 'long',    });    console.log('Multi-Asset Order: ', res);  } catch (e) {    console.error('Submit multi-asset order error: ', e);  }} async function submitMultiAssetBatchOrders() {  try {    const res = await client.submitMultiAssetBatchOrders([      {        contract_code: linearSwapContractCode,        margin_mode: 'cross',        side: 'buy',        type: 'market',        volume: '6',        position_side: 'long',      },    ]);    console.log('Multi-Asset Batch Orders: ', res);  } catch (e) {    console.error('Submit multi-asset batch orders error: ', e);  }} async function submitCoinMDeliveryOrder() {  try {    const res = await client.submitCoinMDeliveryOrder({      symbol: coinMDeliverySymbol,      contract_type: coinMDeliveryContractType,      direction: 'buy',      offset: 'open',      volume: 7,      lever_rate: leverRate,      order_price_type: 'opponent',    });    console.log('Coin-M Delivery Order: ', res);  } catch (e) {    console.error('Submit coin-M delivery order error: ', e);  }} async function submitCoinMDeliveryBatchOrders() {  try {    const res = await client.submitCoinMDeliveryBatchOrders({      orders_data: [        {          symbol: coinMDeliverySymbol,          contract_type: coinMDeliveryContractType,          direction: 'buy',          offset: 'open',          volume: 8,          lever_rate: leverRate,          order_price_type: 'opponent',        },      ],    });    console.log('Coin-M Delivery Batch Orders: ', JSON.stringify(res, null, 2));  } catch (e) {    console.error('Submit coin-M delivery batch orders error: ', e);  }} async function submitCoinMPerpOrder() {  try {    const res = await client.submitCoinMPerpOrder({      contract_code: coinMPerpContractCode,      direction: 'buy',      offset: 'open',      volume: 9,      lever_rate: leverRate,      order_price_type: 'opponent',    });    console.log('Coin-M Perp Order: ', res);  } catch (e) {    console.error('Submit coin-M perp order error: ', e);  }} async function submitCoinMPerpBatchOrders() {  try {    const res = await client.submitCoinMPerpBatchOrders({      orders_data: [        {          contract_code: coinMPerpContractCode,          direction: 'buy',          offset: 'open',          volume: 10,          lever_rate: leverRate,          order_price_type: 'opponent',        },      ],    });    console.log('Coin-M Perp Batch Orders: ', JSON.stringify(res, null, 2));  } catch (e) {    console.error('Submit coin-M perp batch orders error: ', e);  }} async function submitCoinMPerpLightningCloseOrder() {  try {    const res = await client.submitCoinMPerpLightningCloseOrder({      contract_code: coinMPerpContractCode,      volume: 11,      direction: 'sell',      order_price_type: 'lightning',    });    console.log('Coin-M Perp Lightning Close Order: ', res);  } catch (e) {    console.error('Submit coin-M perp lightning close order error: ', e);  }} // Uncomment the function you want to test: // submitLinearSwapIsolatedOrder();// submitLinearSwapCrossOrder();// submitLinearSwapIsolatedBatchOrders();// submitLinearSwapCrossBatchOrders();//submitMultiAssetOrder();// submitMultiAssetBatchOrders();// submitCoinMDeliveryOrder();// submitCoinMDeliveryBatchOrders();// submitCoinMPerpOrder();// submitCoinMPerpBatchOrders();// submitCoinMPerpLightningCloseOrder(); 

Subscribe on Substack

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