KuCoin JavaScript SDK example: authorizationHeader.ts

KuCoin authorization header JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.

This example uses kucoin-api, the JavaScript and TypeScript SDK for KuCoin. Install it with npm install kucoin-api.

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

examples/Kucoin/Auth/authorizationHeader.ts

What this example covers

  • KuCoin authentication and request-signing JavaScript example.
  • Uses the Siebly KuCoin SDK package kucoin-api instead of hand-written signing code.
  • Source path: Kucoin/Auth/authorizationHeader.ts.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getBalances(), setAccessToken().

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.
import { SpotClient } from 'kucoin-api'; async function start() {  /**   * All REST clients support passing the access token. If available, sign will be skipped for the request and the access token will instead be used via an authorization header.   *   * More details: https://github.com/tiagosiebler/kucoin-api/issues/2   */  const client = new SpotClient({    apiAccessToken: 'accessTokenHere!',  });   try {    const result = await client.getBalances();     console.log('result ', JSON.stringify(result, null, 2));  } catch (e) {    console.error('Req error: ', e);  }   // If you later need to set a new access token (e.g. it expired):  client.setAccessToken('newAccessTokenHere');} start(); 

Subscribe on Substack

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