Use this file to discover all available pages before exploring further.
The RestClient is the primary REST API client in the bitmart-api SDK, covering all of BitMart’s spot and margin trading, funding account, deposit/withdrawal, sub-account, and earn endpoints. It targets the main https://api-cloud.bitmart.com base URL and supports API versions v1 through v4, so you always have access to both current and legacy endpoints from a single, unified client.
Most methods accept a plain JavaScript object whose properties map 1-to-1 with the parameters listed in BitMart’s official API documentation. TypeScript users get fully typed request and response objects out of the box.
import { RestClient } from 'bitmart-api';const client = new RestClient({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET', apiMemo: 'YOUR_API_MEMO', // The memo you set when creating your API key});
import { RestClient } from 'bitmart-api';// No credentials needed for public market data endpointsconst client = new RestClient();
getSpotHistoryKlineV3() returns OHLCV candlestick data for a symbol over a specified time range. Each candle is returned as a compact array: [timestamp, open, high, low, close, volume, quoteVolume].
getSpotOrderBookDepthV3() returns the current order book for a symbol, with bids and asks up to the requested depth.
import { RestClient } from 'bitmart-api';const client = new RestClient();async function fetchOrderBook() { try { const book = await client.getSpotOrderBookDepthV3({ symbol: 'BTC_USDT', limit: 20, // Number of price levels on each side (optional, default varies) }); console.log('BTC/USDT order book:', JSON.stringify(book, null, 2)); } catch (e) { console.error('Error fetching order book:', e); }}fetchOrderBook();
Use getSpotRecentTrades() to retrieve the latest executed trades for a symbol, and getSpotTickerV3() to fetch the ticker for a single pair.
The v4 order query endpoints (getSpotOpenOrdersV4, getSpotHistoricOrdersV4, getSpotAccountTradesV4) use POST internally but behave like read operations — pass all filters as object properties.
The SDK throws structured errors when an API call fails. Wrap calls in try/catch blocks to handle both network-level and API-level errors gracefully.
import { RestClient } from 'bitmart-api';const client = new RestClient({ apiKey: process.env.API_KEY!, apiSecret: process.env.API_SECRET!, apiMemo: process.env.API_MEMO!,});async function safeOrderSubmit() { try { const result = await client.submitSpotOrderV2({ symbol: 'BTC_USDT', side: 'buy', type: 'limit', size: '0.001', price: '60000', }); console.log('Order placed successfully:', result.data.order_id); } catch (e: any) { // API errors include a code and message from BitMart if (e.body) { console.error('API error code:', e.body.code); console.error('API error message:', e.body.message); } else { // Network or unexpected error console.error('Unexpected error:', e.message); } }}safeOrderSubmit();
BitMart uses a custom error code system. A successful HTTP 200 response can still carry a non-zero code field indicating a business-logic error (e.g. insufficient balance, invalid symbol). The SDK surfaces these as thrown errors when parseExceptions is true (the default).