HTX Spot Private JavaScript SDK example: account.ts

HTX Spot Private account 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/account.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/account.ts.
  • Example category: Spot Private.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getAccounts(), getAccountBalance(), getAccountValuation(), getAssetValuation(), getAccountLedger(), getFeeRate().

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 ACCOUNT INFORMATION. /** * HTX API uses API Key and API Secret. * * Example: * { *   apiKey: 'your-api-key', *   apiSecret: 'your-api-secret', * } * * API Key Permissions Required: * - Read access for account and balance queries */ const client = new SpotClient({  apiKey: process.env.API_SPOT_KEY || 'insertApiKeyHere',  apiSecret: process.env.API_SPOT_SECRET || 'insertApiSecretHere',}); async function getAccounts() {  try {    const accounts = await client.getAccounts();    console.log('Accounts: ', JSON.stringify(accounts, null, 2));     // Use the spot account id for trading and balance queries    const spotAccount = accounts.data?.find(      (account) => account.type === 'spot',    );    console.log('Spot Account ID: ', spotAccount?.id);  } catch (e) {    console.error('Get accounts error: ', e);  }} async function getAccountBalance() {  try {    const accounts = await client.getAccounts();    const accountId = accounts.data?.find(      (account) => account.type === 'spot',    )?.id;     if (!accountId) {      console.error('No spot account id found');      return;    }     const balance = await client.getAccountBalance({ accountId });    console.log('Account Balance: ', JSON.stringify(balance, null, 2));  } catch (e) {    console.error('Get account balance error: ', e);  }} async function getAccountValuation() {  try {    const valuation = await client.getAccountValuation({});    console.log('Account Valuation: ', JSON.stringify(valuation, null, 2));  } catch (e) {    console.error('Get account valuation error: ', e);  }} async function getAssetValuation() {  try {    const assetValuation = await client.getAssetValuation({      accountType: 'spot',      valuationCurrency: 'BTC',    });    console.log('Asset Valuation: ', JSON.stringify(assetValuation, null, 2));  } catch (e) {    console.error('Get asset valuation error: ', e);  }} async function getAccountLedger() {  try {    const ledger = await client.getAccountLedger({      accountId: '1234567890',      limit: 50,    });    console.log('Account Ledger: ', JSON.stringify(ledger, null, 2));  } catch (e) {    console.error('Get account ledger error: ', e);  }} async function getFeeRate() {  try {    const feeRate = await client.getFeeRate({ symbols: 'btcusdt,ethusdt' });    console.log('Fee Rate: ', JSON.stringify(feeRate, null, 2));  } catch (e) {    console.error('Get fee rate error: ', e);  }} // Uncomment the function you want to test: getAccounts();// getAccountBalance();// getAccountValuation();// getAssetValuation();// getAccountLedger();// getFeeRate(); 

Subscribe on Substack

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