HTX Derivatives Private JavaScript SDK example: account.ts

HTX Derivatives 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/Derivatives/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/Derivatives/Private/account.ts.
  • Example category: Derivatives Private.
  • Imports SDK symbols including FuturesClient.
  • Calls SDK methods such as getLinearSwapAccountType(), getLinearSwapCrossAccountInfo(), getLinearSwapCrossPositions(), getLinearSwapCrossFills(), getMultiAssetAccountBalance(), getLinearSwapFinancialRecords(), transferLinearSwapInner(), getMultiAssetPositions().

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 { FuturesClient } from '@siebly/htx-api'; // This example shows how to call HTX Derivatives API endpoints for ACCOUNT INFORMATION. const client = new FuturesClient({  apiKey: process.env.API_FUTURES_KEY || 'insertApiKeyHere',  apiSecret: process.env.API_FUTURES_SECRET || 'insertApiSecretHere',}); const contractCode = 'BTC-USDT'; async function getLinearSwapAccountType() {  try {    const accountType = await client.getLinearSwapAccountType();    console.log('Account Type: ', JSON.stringify(accountType, null, 2));  } catch (e) {    console.error('Get account type error: ', e);  }} async function getCrossAccountInfo() {  try {    const accountInfo = await client.getLinearSwapCrossAccountInfo();    console.log('Cross Account Info: ', JSON.stringify(accountInfo, null, 2));  } catch (e) {    console.error('Get cross account info error: ', e);  }} async function getCrossPositions() {  try {    const positions = await client.getLinearSwapCrossPositions({      contract_code: contractCode,    });    console.log('Cross Positions: ', JSON.stringify(positions, null, 2));  } catch (e) {    console.error('Get cross positions error: ', e);  }} async function getCrossFills() {  try {    const fills = await client.getLinearSwapCrossFills({      contract: contractCode,      trade_type: 0,    });    console.log('Cross Fills: ', JSON.stringify(fills, null, 2));  } catch (e) {    console.error('Get cross fills error: ', e);  }} async function getMultiAssetAccountBalance() {  try {    const balance = await client.getMultiAssetAccountBalance();    console.log(      'Multi-Asset Account Balance: ',      JSON.stringify(balance, null, 2),    );  } catch (e) {    console.error('Get multi-asset account balance error: ', e);  }} async function getFinancialRecords() {  try {    const records = await client.getLinearSwapFinancialRecords({      mar_acct: 'USDT',      contract: contractCode,      type: '3,4,5,6',    });    console.log('Financial Records: ', JSON.stringify(records, null, 2));  } catch (e) {    console.error('Get financial records error: ', e);  }} async function transferLinearSwapInner() {  try {    const transfer = await client.transferLinearSwapInner({      asset: 'USDT',      from_margin_account: 'USDT',      to_margin_account: contractCode,      amount: '10',    });    console.log('Inner Transfer Result: ', JSON.stringify(transfer, null, 2));  } catch (e) {    console.error('Transfer linear swap inner error: ', e);  }} async function getMultiAssetPositions() {  try {    const positions = await client.getMultiAssetPositions({      contract_code: contractCode,    });    console.log('Multi-Asset Positions: ', JSON.stringify(positions, null, 2));  } catch (e) {    console.error('Get multi-asset positions error: ', e);  }} // Uncomment the function you want to test: // getLinearSwapAccountType();// getCrossAccountInfo();// getCrossPositions();// getCrossFills();// getMultiAssetAccountBalance();// getFinancialRecords();// transferLinearSwapInner();// getMultiAssetPositions(); 

Subscribe on Substack

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