Skip to content

Account access and balances ​

Public prices do not require credentials. Private methods require an HTX API key and secret with the relevant permissions. Start with read-only access and keep withdrawal permission disabled unless your application specifically needs it.

Create an authenticated client ​

Set HTX_API_KEY and HTX_API_SECRET in your server environment. Do not put secrets in frontend code, mobile apps, logs or committed files.

ts
import { SpotClient } from '@siebly/htx-api';

const apiKey = process.env.HTX_API_KEY;
const apiSecret = process.env.HTX_API_SECRET;
if (!apiKey || !apiSecret) {
  throw new Error('Set HTX_API_KEY and HTX_API_SECRET on your server.');
}

export const client = new SpotClient({ apiKey, apiSecret });

The SDK signs private requests with the API key and secret. The access-token setters do not replace those credentials. Keep the server clock synchronized and use credentials for the same account and product as the selected endpoint.

Select a Spot account and read balances ​

HTX Spot trading uses an account ID in addition to the API credentials. Discover it with getAccounts() rather than substituting your user ID:

ts
import { client } from './authenticated-client';

async function main() {
  const accounts = await client.getAccounts();
  const account = accounts.data.find(
    (item) => item.type === 'spot' && item.state === 'working',
  );
  if (!account) {
    throw new Error('No active Spot account found.');
  }
  const balances = await client.getAccountBalance({ accountId: account.id });
  console.log('Spot account:', account.id);
  console.log('Balance rows received:', balances.data.list.length);
}

main().catch(() => {
  console.error(
    'Account read failed. Check credentials, permissions and account access.',
  );
  process.exitCode = 1;
});

Select the intended account explicitly if your application uses more than one. Balance rows distinguish currency and balance type; a frozen amount is not spendable. Preserve string amounts when storing balances.

Futures and private streams ​

FuturesClient uses the same credential option names, but account modes, endpoints and permissions differ. Configure a separate WebsocketClient for private streams; constructing a REST client does not authenticate another client.

Private account updates · Configuration · Error handling

Built by Siebly. Open source SDKs for exchange APIs.