Binance JavaScript SDK example: rest-spot-public.ts

Binance REST spot public JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Binance/REST/Spot/rest-spot-public.ts

What this example covers

  • Binance REST API JavaScript example.
  • Uses the Siebly Binance SDK package binance instead of hand-written HTTP request plumbing.
  • Source path: Binance/REST/Spot/rest-spot-public.ts.
  • Imports SDK symbols including MainClient.
  • Calls SDK methods such as getAvgPrice(), getExchangeInfo(), get24hrChangeStatistics().

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 { MainClient } from 'binance'; const client = new MainClient({  // Optional (default: false) - when true, response strings are parsed to floats (only for known keys).  // beautifyResponses: true,}); (async () => {  try {    // console.log(    //   'getAvgPrice: ',    //   await client.getAvgPrice({ symbol: 'BTCUSDT' }),    // );    // console.log(    //   'getExchangeInfo: ',    //   JSON.stringify(await client.getExchangeInfo(), null, 2),    // );     const oneTicker = await client.get24hrChangeStatistics({      symbol: 'BTCUSDT',    });    console.log('getTickers', oneTicker);     const manyTickers = await client.get24hrChangeStatistics({      symbols: ['BTCUSDT', 'ETHUSDT'],    });    console.log('getTickers many', manyTickers);    const allTickers = await client.get24hrChangeStatistics();    console.log('getTickers all', allTickers);  } catch (e) {    console.error('request failed: ', e);  }})(); 

Subscribe on Substack

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