HTX Spot Public JavaScript SDK example: marketData.ts

HTX Spot 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/Spot/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/Spot/Public/marketData.ts.
  • Example category: Spot Public.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getTimestamp(), getMarketStatus(), getTradingSymbols(), getTicker(), getTickers(), getMarketDepth(), getKlines(), getLastTrade(), getHistoryTrades().

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.
import { SpotClient } from '@siebly/htx-api'; // This example shows how to call HTX Spot API endpoints with Node.js or TypeScript// using the npm module "@siebly/htx-api" for PUBLIC MARKET DATA (no authentication). // Public calls do not require API keysconst client = new SpotClient(); async function publicCalls() {  try {    const timestamp = await client.getTimestamp();    console.log('Server Timestamp: ', timestamp);     const marketStatus = await client.getMarketStatus();    console.log('Market Status: ', marketStatus);     const symbols = await client.getTradingSymbols();    console.log('Trading Symbols: ', symbols);     const ticker = await client.getTicker({ symbol: 'btcusdt' });    console.log('Ticker (btcusdt): ', ticker);     const tickers = await client.getTickers();    console.log('All Tickers: ', tickers);     const orderBook = await client.getMarketDepth({      symbol: 'btcusdt',      depth: 10,      type: 'step0',    });    console.log('Order Book: ', orderBook);     const klines = await client.getKlines({      symbol: 'btcusdt',      period: '1min',      size: 10,    });    console.log('Klines: ', klines);     const lastTrade = await client.getLastTrade({ symbol: 'btcusdt' });    console.log('Last Trade: ', lastTrade);     const historyTrades = await client.getHistoryTrades({      symbol: 'btcusdt',      size: 10,    });    console.log('History Trades: ', historyTrades);  } catch (e) {    console.error('Error: ', e);  }} publicCalls(); 

Subscribe on Substack

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