Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bitmart-api/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through installing the bitmart-api SDK, fetching public market data without any credentials, and then making authenticated calls using your BitMart API key. By the end you will have a working client that can read account balances and subscribe to a live WebSocket ticker.
1
Install the package
2
Add bitmart-api to your project using your preferred package manager.
3
npm
npm install bitmart-api
yarn
yarn add bitmart-api
pnpm
pnpm add bitmart-api
4
The package uses the Web Crypto API for request signing. Node.js v18 has reached end of life — the current Node.js LTS (v22 or above) is recommended. If you need to run on an older release, inject a custom customSignMessageFn using Node’s native createHmac as shown in the Authentication page.
5
Import and create a client
6
The SDK ships both ESM and CommonJS builds, so the same package works in any Node.js project.
7
TypeScript / ESM
import { RestClient } from 'bitmart-api';

const client = new RestClient();
CommonJS
const { RestClient } = require('bitmart-api');

const client = new RestClient();
8
No arguments are needed for public endpoints — the client works without API credentials for any unauthenticated call.
9
Fetch public market data
10
Public endpoints require no API key. The example below retrieves the latest tickers for all spot trading pairs.
11
import { RestClient } from 'bitmart-api';

const client = new RestClient();

async function getSpotTickers() {
  try {
    const tickers = await client.getSpotTickersV3();
    console.log('Tickers:', JSON.stringify(tickers, null, 2));
  } catch (e) {
    console.error('Request error:', e);
  }
}

getSpotTickers();
12
All SDK methods return Promises, so you can use either async/await (shown above) or .then() / .catch() chaining.
13
Create an authenticated client
14
Private endpoints — such as reading your account balance or placing an order — require API credentials. Create your keys at https://www.bitmart.com/api-settings and store them in environment variables.
15
TypeScript / ESM
import { RestClient } from 'bitmart-api';

const client = new RestClient({
  apiKey: process.env.BITMART_API_KEY!,
  apiSecret: process.env.BITMART_API_SECRET!,
  apiMemo: process.env.BITMART_API_MEMO!,
});
CommonJS
const { RestClient } = require('bitmart-api');

const client = new RestClient({
  apiKey: process.env.BITMART_API_KEY,
  apiSecret: process.env.BITMART_API_SECRET,
  apiMemo: process.env.BITMART_API_MEMO,
});
16
All three fields — apiKey, apiSecret, and apiMemo — are required together. Providing only one or two will throw an error at construction time.
17
Fetch your account balances
18
With an authenticated client you can call private endpoints such as getAccountBalancesV1.
19
import { RestClient } from 'bitmart-api';

const client = new RestClient({
  apiKey: process.env.BITMART_API_KEY!,
  apiSecret: process.env.BITMART_API_SECRET!,
  apiMemo: process.env.BITMART_API_MEMO!,
});

async function getBalances() {
  try {
    const balances = await client.getAccountBalancesV1();
    console.log('Account balances:', JSON.stringify(balances, null, 2));
  } catch (e) {
    console.error('Request error:', e);
  }
}

getBalances();
20
Place a spot order
21
Once your client is authenticated you can submit orders. The example below places a market sell order using submitSpotOrderV2.
22
import { RestClient } from 'bitmart-api';

const client = new RestClient({
  apiKey: process.env.BITMART_API_KEY!,
  apiSecret: process.env.BITMART_API_SECRET!,
  apiMemo: process.env.BITMART_API_MEMO!,
});

async function placeOrder() {
  try {
    const result = await client.submitSpotOrderV2({
      symbol: 'BTC_USDT',
      side: 'sell',
      type: 'market',
      size: '0.0001',
    });
    console.log('Order submitted:', JSON.stringify(result, null, 2));
  } catch (e) {
    console.error('Order error:', e);
  }
}

placeOrder();
23
The example above submits a real market order if run against the live environment. Test with very small sizes or use the FuturesClientV2 with demoTrading: true for simulated trading.
24
Subscribe to a live WebSocket ticker
25
The WebsocketClient handles connections, heartbeats, and reconnections automatically. For public streams, no API credentials are required.
26
import { WebsocketClient } from 'bitmart-api';

const wsClient = new WebsocketClient();

// Connection opened
wsClient.on('open', (data) => {
  console.log('WebSocket connected:', data?.wsKey);
});

// Market data received
wsClient.on('update', (data) => {
  console.log('Ticker update:', JSON.stringify(data, null, 2));
});

// Transparent reconnection — client resubscribes automatically
wsClient.on('reconnected', (data) => {
  console.log('WebSocket reconnected:', data);
});

// Handle errors
wsClient.on('exception', (data) => {
  console.error('WebSocket error:', data);
});

// Subscribe to the BTC/USDT spot ticker
wsClient.subscribe('spot/ticker:BTC_USDT', 'spot');

Next steps

Authentication

Understand how the API key, secret, and memo combine to produce signed requests.

REST Client Reference

Browse all available methods on RestClient and FuturesClientV2.

WebSocket Overview

Subscribe to private account streams and handle real-time order and position updates.

Demo Trading

Use BitMart’s simulated environment to test futures strategies risk-free.

Build docs developers (and LLMs) love