BitMart Auth JavaScript SDK example: fasterHmacSign.ts

BitMart Auth faster hmac sign JavaScript example for the Siebly BitMart 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/Bitmart/Auth/fasterHmacSign.ts

What this example covers

  • BitMart authentication and request-signing JavaScript example.
  • Uses the Siebly BitMart SDK package bitmart-api instead of hand-written signing code.
  • Source path: Bitmart/Auth/fasterHmacSign.ts.
  • Example category: Auth.
  • Imports SDK symbols including RestClient.
  • Calls SDK methods such as getAccountBalancesV1().

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 { RestClient } from 'bitmart-api';import { createHmac } from 'crypto'; const account = {  key: process.env.API_KEY || 'apiKeyHere',  secret: process.env.API_SECRET || 'apiSecretHere',  memo: process.env.API_MEMO || 'apiMemoHere',}; const client = new RestClient({  apiKey: account.key,  apiSecret: account.secret,  apiMemo: account.memo,  /**   * Overkill in almost every case, but if you need any optimisation available,   * you can inject a faster sign mechanism such as node's native createHmac:   */  customSignMessageFn: async (message, secret) => {    return createHmac('sha256', secret).update(message).digest('hex');  },}); async function getSpotBalances() {  try {    const balances = await client.getAccountBalancesV1();     console.log('Balances: ', JSON.stringify(balances, null, 2));  } catch (e) {    console.error('Req error: ', e);  }} getSpotBalances(); 

Subscribe on Substack

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