HTX Spot Private JavaScript SDK example: depositWithdraw.ts

HTX Spot Private deposit withdraw 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/depositWithdraw.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/depositWithdraw.ts.
  • Example category: Spot Private.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getDepositAddress(), getWithdrawQuota(), getWithdrawAddress(), submitWithdraw(), generateNewOrderID(), getDepositWithdrawHistory(), cancelWithdraw(), submitFuturesTransfer(), submitSubUserTransfer().

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 DEPOSIT AND WITHDRAWAL. const client = new SpotClient({  apiKey: process.env.API_SPOT_KEY || 'insertApiKeyHere',  apiSecret: process.env.API_SPOT_SECRET || 'insertApiSecretHere',}); async function getDepositAddress() {  try {    const depositAddress = await client.getDepositAddress({ currency: 'btc' });    console.log('Deposit Address: ', JSON.stringify(depositAddress, null, 2));  } catch (e) {    console.error('Get deposit address error: ', e);  }} async function getWithdrawQuota() {  try {    const withdrawQuota = await client.getWithdrawQuota({ currency: 'btc' });    console.log('Withdraw Quota: ', JSON.stringify(withdrawQuota, null, 2));  } catch (e) {    console.error('Get withdraw quota error: ', e);  }} async function getWithdrawAddress() {  try {    const withdrawAddress = await client.getWithdrawAddress({      currency: 'btc',    });    console.log(      'Withdraw Addresses: ',      JSON.stringify(withdrawAddress, null, 2),    );  } catch (e) {    console.error('Get withdraw address error: ', e);  }} async function submitWithdraw() {  try {    const withdrawal = await client.submitWithdraw({      address: 'your-withdraw-address-here',      currency: 'usdt',      amount: '10',      fee: 0,      chain: 'trc20usdt',      'client-order-id': client.generateNewOrderID(),    });    console.log('Withdrawal Result: ', JSON.stringify(withdrawal, null, 2));  } catch (e) {    console.error('Submit withdraw error: ', e);  }} async function getDepositWithdrawHistory() {  try {    const deposits = await client.getDepositWithdrawHistory({      type: 'deposit',      currency: 'btc',    });    console.log('Deposit History: ', JSON.stringify(deposits, null, 2));     const withdrawals = await client.getDepositWithdrawHistory({      type: 'withdraw',      currency: 'btc',    });    console.log('Withdraw History: ', JSON.stringify(withdrawals, null, 2));  } catch (e) {    console.error('Get deposit/withdraw history error: ', e);  }} async function cancelWithdraw() {  try {    const cancelResult = await client.cancelWithdraw({ withdrawId: 123456789 });    console.log(      'Cancel Withdraw Result: ',      JSON.stringify(cancelResult, null, 2),    );  } catch (e) {    console.error('Cancel withdraw error: ', e);  }} async function transferSpotToFutures() {  try {    const transfer = await client.submitFuturesTransfer({      currency: 'usdt',      amount: '10',      type: 'pro-to-futures',    });    console.log(      'Spot to Futures Transfer: ',      JSON.stringify(transfer, null, 2),    );  } catch (e) {    console.error('Transfer spot to futures error: ', e);  }} async function transferToSubUser() {  try {    const transfer = await client.submitSubUserTransfer({      'sub-uid': 123456789,      currency: 'usdt',      amount: '10',      type: 'master-transfer-in',    });    console.log('Sub User Transfer: ', JSON.stringify(transfer, null, 2));  } catch (e) {    console.error('Transfer to sub user error: ', e);  }} // Uncomment the function you want to test: getDepositAddress();// getWithdrawQuota();// getWithdrawAddress();// submitWithdraw();// getDepositWithdrawHistory();// cancelWithdraw();// transferSpotToFutures();// transferToSubUser(); 

Subscribe on Substack

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