---
title: "HTX Spot Private Account JavaScript SDK Example | Siebly"
description: "HTX Spot Private account 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/account"
robots: "index,follow"
---

# HTX Spot Private Account JavaScript SDK Example

HTX Spot Private account 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) / [account.ts](/examples/HTX/Spot/Private/account)

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

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

## account.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 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();
```
