This guide walks you through installing theDocumentation 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.
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.
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.No arguments are needed for public endpoints — the client works without API credentials for any unauthenticated call.
Public endpoints require no API key. The example below retrieves the latest tickers for all spot trading pairs.
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();
All SDK methods return Promises, so you can use either
async/await (shown above) or .then() / .catch() chaining.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.
All three fields —
apiKey, apiSecret, and apiMemo — are required together. Providing only one or two will throw an error at construction time.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();
Once your client is authenticated you can submit orders. The example below places a market sell order using
submitSpotOrderV2.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();
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.The
WebsocketClient handles connections, heartbeats, and reconnections automatically. For public streams, no API credentials are required.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.