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.
@siebly/htx-api instead of hand-written HTTP request plumbing.HTX/Spot/Private/account.ts.SpotClient.getAccounts(), getAccountBalance(), getAccountValuation(), getAssetValuation(), getAccountLedger(), getFeeRate()./* 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(); We use essential cookies and optional analytics. Read the Privacy Policy.
Essential cookies stay on. Toggle analytics if you want to share anonymous usage insights. You can revisit this anytime via Cookie Settings in the footer.