HTX Derivatives Public JavaScript SDK example: marketData.ts

HTX Derivatives Public market data 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/Public/marketData.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/Public/marketData.ts.
  • Example category: Derivatives Public.
  • Imports SDK symbols including FuturesClient.
  • Calls SDK methods such as getTimestamp(), getLinearSwapTickers(), getLinearSwapTicker(), getLinearSwapMarketDepth(), getLinearSwapKlines(), getLinearSwapTradeHistory(), getLinearSwapFundingRate(), getLinearSwapContractInfo(), getLinearSwapOpenInterest().

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.
  • 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 PUBLIC MARKET DATA// (linear swap, no authentication required). const client = new FuturesClient();const contractCode = 'BTC-USDT'; async function getTimestamp() {  try {    const timestamp = await client.getTimestamp();    console.log('Server Timestamp: ', timestamp);  } catch (e) {    console.error('Get timestamp error: ', e);  }} async function getAllTickers() {  try {    const allTickers = await client.getLinearSwapTickers();    console.log(      'All Linear Swap Tickers: ',      JSON.stringify(allTickers, null, 2),    );  } catch (e) {    console.error('Get all tickers error: ', e);  }} async function getTickerByContract() {  try {    const ticker = await client.getLinearSwapTicker({      contract_code: contractCode,    });    console.log('Ticker: ', JSON.stringify(ticker, null, 2));  } catch (e) {    console.error('Get ticker error: ', e);  }} async function getOrderBook() {  try {    const orderBook = await client.getLinearSwapMarketDepth({      contract_code: contractCode,      type: 'step0',    });    console.log('Order Book: ', JSON.stringify(orderBook, null, 2));  } catch (e) {    console.error('Get order book error: ', e);  }} async function getKlines() {  try {    const klines = await client.getLinearSwapKlines({      contract_code: contractCode,      period: '60min',      size: 10,    });    console.log('Klines: ', JSON.stringify(klines, null, 2));  } catch (e) {    console.error('Get klines error: ', e);  }} async function getTradeHistory() {  try {    const tradeHistory = await client.getLinearSwapTradeHistory({      contract_code: contractCode,      size: 20,    });    console.log('Trade History: ', JSON.stringify(tradeHistory, null, 2));  } catch (e) {    console.error('Get trade history error: ', e);  }} async function getFundingRate() {  try {    const fundingRate = await client.getLinearSwapFundingRate({      contract_code: contractCode,    });    console.log('Funding Rate: ', JSON.stringify(fundingRate, null, 2));  } catch (e) {    console.error('Get funding rate error: ', e);  }} async function getContractInfo() {  try {    const contractInfo = await client.getLinearSwapContractInfo({      contract_code: contractCode,    });    console.log('Contract Info: ', JSON.stringify(contractInfo, null, 2));  } catch (e) {    console.error('Get contract info error: ', e);  }} async function getOpenInterest() {  try {    const openInterest = await client.getLinearSwapOpenInterest({      contract_code: contractCode,    });    console.log('Open Interest: ', JSON.stringify(openInterest, null, 2));  } catch (e) {    console.error('Get open interest error: ', e);  }} // Uncomment the function you want to test: // getTimestamp();// getAllTickers();// getTickerByContract();// getOrderBook();// getKlines();// getTradeHistory();// getFundingRate();// getContractInfo();// getOpenInterest(); 

Subscribe on Substack

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