BitMart JavaScript SDK

Installation and integration guidance for the BitMart SDK in JavaScript.

JavaScript SDK Usage

Use framework-neutral JavaScript request and event flows across Node.js-compatible runtimes.

In JavaScript, use the package directly from readable examples. TypeScript remains useful for larger integrations, but the same client patterns work in plain JavaScript.

What This SDK Covers

  • Complete BitMart REST API integrations for exchange-specific workflows.
  • Robust BitMart WebSocket support for market and account stream handling.
  • JavaScript-friendly usage patterns for production integration work.
  • Adaptable JavaScript examples & guides under /examples for implementation reference.
  • Framework-neutral JavaScript snippets that stay approachable in all JavaScript runtimes.

Install Package

npm install bitmart-api
# or
pnpm install bitmart-api
yarn add bitmart-api

Quickstart REST API Walkthrough

Easily start calling Bitmart's spot REST APIs in JavaScript.

  • Install the Bitmart JavaScript SDK via NPM: npm install bitmart-api.
  • Import the RestClient class (REST API wrapper for Bitmart APIs).
  • Create an authenticated RestClient instance with your API credentials (apiKey, apiSecret, apiMemo).
  • Call REST API methods as functions and await the promise containing the response.

In this example, we:

  • Prepare an authenticated REST client using environment variables.
  • Submit a spot market sell order on BTC_USDT using submitSpotOrderV2.
  • Log the full API response to the console.

Commented examples are also included in the script to show how to prepare market and limit buy order payloads.

For a full map of available REST API methods, check out the endpoint reference below.

Quickstart REST API Example

import { RestClient } from 'bitmart-api';

const account = {
  key: process.env.API_KEY || 'apiKeyHere',
  secret: process.env.API_SECRET || 'apiSecretHere',
  memo: process.env.API_MEMO || 'apiMemoHere',
};

async function start() {
  const client = new RestClient({
    apiKey: account.key,
    apiSecret: account.secret,
    apiMemo: account.memo,
  });

  try {
    // const usdValue = 6;
    // const price = 52000;
    // const qty = usdValue / price;

    // const limitBuyOrder = {
    //   symbol: 'BTC_USDT',
    //   side: 'buy',
    //   type: 'limit',
    //   size: String(qty),
    //   price: String(price),
    // };

    // const res = await client.submitSpotOrder({
    //   symbol: 'BTC_USDT',
    //   side: 'buy',
    //   type: 'market',
    //   size: String(qty),
    // });

    const res = await client.submitSpotOrderV2({
      symbol: 'BTC_USDT',
      side: 'sell',
      type: 'market',
      size: String(0.00011),
    });
    console.log('res ', JSON.stringify(res, null, 2));
  } catch (e) {
    console.error('Req error: ', e);
  }
}

start();

Quickstart WebSocket Walkthrough

Connecting to Bitmart's private spot WebSocket streams is straightforward with the WebsocketClient.

  • Install the Bitmart JavaScript SDK via NPM: npm install bitmart-api.
  • Import the WebsocketClient and (optionally) a custom logger.
  • Create an authenticated WebsocketClient instance with your API credentials (apiKey, apiSecret, apiMemo).
  • Configure event handlers for key events such as open, update, response, reconnect, reconnected, close, authenticated, and exception.
  • Subscribe to private spot topics and process incoming updates in real time.

In this example, we:

  • Open an authenticated private WebSocket connection for spot.
  • Subscribe to order progress updates for BTC_USDT.
  • Demonstrate an additional (commented) private balance update topic.

This setup allows you to consume live account-level trading events without polling REST endpoints.

Quickstart WebSocket Example

import { LogParams, WebsocketClient } from 'bitmart-api';

const account = {
  key: process.env.API_KEY || 'apiKeyHere',
  secret: process.env.API_SECRET || 'apiSecretHere',
  memo: process.env.API_MEMO || 'apiMemoHere',
};

const customLogger = {
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  trace: (...params: LogParams): void => {
    console.log('trace', ...params);
  },
  info: (...params: LogParams): void => {
    console.log('info', ...params);
  },
  error: (...params: LogParams): void => {
    console.error('error', ...params);
  },
};

async function start() {
  const client = new WebsocketClient(
    {
      apiKey: account.key,
      apiSecret: account.secret,
      apiMemo: account.memo,
    },
    customLogger,
  );

  client.on('open', (data) => {
    console.log('connected ', data?.wsKey);
  });

  // Data received
  client.on('update', (data) => {
    console.info('data received: ', JSON.stringify(data));
  });

  // Something happened, attempting to reconenct
  client.on('reconnect', (data) => {
    console.log('reconnect: ', data);
  });

  // Reconnect successful
  client.on('reconnected', (data) => {
    console.log('reconnected: ', data);
  });

  // Connection closed. If unexpected, expect reconnect -> reconnected.
  client.on('close', (data) => {
    console.error('close: ', data);
  });

  // Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"
  client.on('response', (data) => {
    console.info('response: ', data);
  });

  client.on('exception', (data) => {
    console.error('exception: ', data);
  });

  client.on('authenticated', (data) => {
    console.error('authenticated: ', data);
  });

  try {
    // order progress
    client.subscribe('spot/user/order:BTC_USDT', 'spot');

    // balance updates
    // client.subscribe('spot/user/balance:BALANCE_UPDATE', 'spot');
  } catch (e) {
    console.error('Req error: ', e);
  }
}

start();

Endpoint Function Reference

Endpoint maps

Each REST client is a JavaScript class, which provides functions individually mapped to each endpoint available in the exchange's API offering.

The following table shows all methods available in each REST client, whether the method requires authentication (automatically handled if API keys are provided), as well as the exact endpoint each method is connected to.

This can be used to easily find which method to call, once you have found which endpoint you're looking to use.

All REST clients are in the src folder. For usage examples, make sure to check the examples folder.

List of clients:

If anything is missing or wrong, please open an issue or let us know in our Node.js Traders telegram group!

How to use table

Table consists of 4 parts:

  • Function name
  • AUTH
  • HTTP Method
  • Endpoint

Function name is the name of the function that can be called through the SDK. Check examples folder in the repo for more help on how to use them!

AUTH is a boolean value that indicates if the function requires authentication - which means you need to pass your API key and secret to the SDK.

HTTP Method shows HTTP method that the function uses to call the endpoint. Sometimes endpoints can have same URL, but different HTTP method so you can use this column to differentiate between them.

Endpoint is the URL that the function uses to call the endpoint. Best way to find exact function you need for the endpoint is to search for URL in this table and find corresponding function name.

RestClient.ts

This table includes all endpoints from the official Exchange API docs and corresponding SDK functions for each endpoint that are found in RestClient.ts.

FunctionAUTHHTTP MethodEndpoint
getSystemTime()GETsystem/time
getSystemStatus()GETsystem/service
getSpotCurrenciesV1()GETspot/v1/currencies
getSpotTradingPairsV1()GETspot/v1/symbols
getSpotTradingPairDetailsV1()GETspot/v1/symbols/details
getSpotTickersV3()GETspot/quotation/v3/tickers
getSpotTickerV3()GETspot/quotation/v3/ticker
getSpotLatestKlineV3()GETspot/quotation/v3/lite-klines
getSpotHistoryKlineV3()GETspot/quotation/v3/klines
getSpotOrderBookDepthV3()GETspot/quotation/v3/books
getSpotRecentTrades()GETspot/quotation/v3/trades
getSpotTickersV2()GETspot/v2/ticker
getSpotTickerV1()GETspot/v1/ticker_detail
getSpotKLineStepsV1()GETspot/v1/steps
getSpotKlinesV1()GETspot/v1/symbols/kline
getSpotOrderBookDepthV1()GETspot/v1/symbols/book
getAccountBalancesV1()🔐GETaccount/v1/wallet
getAccountCurrenciesV1()GETaccount/v1/currencies
getSpotWalletBalanceV1()🔐GETspot/v1/wallet
getAccountDepositAddressV1()🔐GETaccount/v1/deposit/address
getAccountWithdrawQuotaV1()🔐GETaccount/v1/withdraw/charge
submitWithdrawalV1()🔐POSTaccount/v1/withdraw/apply
getWithdrawAddressList()🔐GETaccount/v1/withdraw/address/list
getDepositWithdrawHistoryV2()🔐GETaccount/v2/deposit-withdraw/history
getDepositWithdrawDetailV1()🔐GETaccount/v1/deposit-withdraw/detail
getMarginAccountDetailsV1()🔐GETspot/v1/margin/isolated/account
submitMarginAssetTransferV1()🔐POSTspot/v1/margin/isolated/transfer
getBasicSpotFeeRateV1()🔐GETspot/v1/user_fee
getActualSpotTradeFeeRateV1()🔐GETspot/v1/trade_fee
submitSpotOrderV2()🔐POSTspot/v2/submit_order
submitMarginOrderV1()🔐POSTspot/v1/margin/submit_order
submitSpotBatchOrdersV2()🔐POSTspot/v2/batch_orders
cancelSpotOrderV3()🔐POSTspot/v3/cancel_order
submitSpotBatchOrdersV4()🔐POSTspot/v4/batch_orders
cancelSpotBatchOrdersV4()🔐POSTspot/v4/cancel_orders
cancelAllSpotOrders()🔐POSTspot/v4/cancel_all
cancelSpotOrdersV1()🔐POSTspot/v1/cancel_orders
getSpotOrderByIdV4()🔐POSTspot/v4/query/order
getSpotOrderByClientOrderIdV4()🔐POSTspot/v4/query/client-order
getSpotOpenOrdersV4()🔐POSTspot/v4/query/open-orders
getSpotHistoricOrdersV4()🔐POSTspot/v4/query/history-orders
getSpotAccountTradesV4()🔐POSTspot/v4/query/trades
getSpotAccountOrderTradesV4()🔐POSTspot/v4/query/order-trades
submitSpotAlgoOrderV4()🔐POSTspot/v4/algo/submit_order
cancelSpotAlgoOrderV4()🔐POSTspot/v4/algo/cancel_order
cancelAllSpotAlgoOrdersV4()🔐POSTspot/v4/algo/cancel_all
getSpotAlgoOrderByIdV4()🔐POSTspot/v4/query/algo/order
getSpotAlgoOrderByClientOrderIdV4()🔐POSTspot/v4/query/algo/client-order
getSpotAlgoOpenOrdersV4()🔐POSTspot/v4/query/algo/open-orders
getSpotAlgoHistoryOrdersV4()🔐POSTspot/v4/query/algo/history-orders
marginBorrowV1()🔐POSTspot/v1/margin/isolated/borrow
marginRepayV1()🔐POSTspot/v1/margin/isolated/repay
getMarginBorrowRecordV1()🔐GETspot/v1/margin/isolated/borrow_record
getMarginRepayRecordV1()🔐GETspot/v1/margin/isolated/repay_record
getMarginBorrowingRatesV1()🔐GETspot/v1/margin/isolated/pairs
submitMainTransferSubToMainV1()🔐POSTaccount/sub-account/main/v1/sub-to-main
submitSubTransferSubToMainV1()🔐POSTaccount/sub-account/sub/v1/sub-to-main
submitMainTransferMainToSubV1()🔐POSTaccount/sub-account/main/v1/main-to-sub
submitMainTransferSubToSubV1()🔐POSTaccount/sub-account/main/v1/sub-to-sub
submitSubTransferSubToSubV1()🔐POSTaccount/sub-account/sub/v1/sub-to-sub
getSubTransfersV1()🔐GETaccount/sub-account/main/v1/transfer-list
getAccountSubTransfersV1()🔐GETaccount/sub-account/v1/transfer-history
getSubSpotWalletBalancesV1()🔐GETaccount/sub-account/main/v1/wallet
getSubAccountsV1()🔐GETaccount/sub-account/main/v1/subaccount-list
getFuturesContractDetails()GETcontract/public/details
getFuturesContractDepth()GETcontract/public/depth
getFuturesOpenInterest()GETcontract/public/open-interest
getFuturesFundingRate()GETcontract/public/funding-rate
getFuturesKlines()GETcontract/public/kline
getFuturesAccountAssets()🔐GETcontract/private/assets-detail
getFuturesAccountOrder()🔐GETcontract/private/order
getFuturesAccountOrderHistory()🔐GETcontract/private/order-history
getFuturesAccountOpenOrders()🔐GETcontract/private/get-open-orders
getFuturesAccountPlanOrders()🔐GETcontract/private/current-plan-order
getFuturesAccountPositions()🔐GETcontract/private/position
getPositionRiskDetails()🔐GETcontract/private/position-risk
getFuturesAccountTrades()🔐GETcontract/private/trades
getFuturesTransfers()🔐GETaccount/v1/transfer-contract-list
submitFuturesOrder()🔐POSTcontract/private/submit-order
cancelFuturesOrder()🔐POSTcontract/private/cancel-order
cancelAllFuturesOrders()🔐POSTcontract/private/cancel-orders
submitFuturesPlanOrder()🔐POSTcontract/private/submit-plan-order
cancelFuturesPlanOrder()🔐POSTcontract/private/cancel-plan-order
submitFuturesTransfer()🔐POSTaccount/v1/transfer-contract
setFuturesLeverage()🔐POSTcontract/private/submit-leverage
submitFuturesSubToMainTransferFromMain()🔐POSTaccount/contract/sub-account/main/v1/sub-to-main
submitFuturesMainToSubTransferFromMain()🔐POSTaccount/contract/sub-account/main/v1/main-to-sub
submitFuturesSubToMainSubFromSub()🔐POSTaccount/contract/sub-account/sub/v1/sub-to-main
getFuturesSubWallet()🔐GETaccount/contract/sub-account/main/v1/wallet
getFuturesSubTransfers()🔐GETaccount/contract/sub-account/main/v1/transfer-list
getFuturesSubTransferHistory()🔐GETaccount/contract/sub-account/v1/transfer-history
getFuturesAffiliateRebates()🔐GETcontract/private/affiliate/rebate-list
getFuturesAffiliateTrades()🔐GETcontract/private/affiliate/trade-list
getBrokerRebate()🔐GETspot/v1/broker/rebate

FuturesClientV2.ts

This table includes all endpoints from the official Exchange API docs and corresponding SDK functions for each endpoint that are found in FuturesClientV2.ts.

FunctionAUTHHTTP MethodEndpoint
getSystemTime()GETsystem/time
getSystemStatus()GETsystem/service
getFuturesContractDetails()GETcontract/public/details
getFuturesContractDepth()GETcontract/public/depth
getFuturesMarketTrade()GETcontract/public/market-trade
getFuturesOpenInterest()GETcontract/public/open-interest
getFuturesFundingRate()GETcontract/public/funding-rate
getFuturesKlines()GETcontract/public/kline
getFuturesMarkPriceKlines()GETcontract/public/markprice-kline
getFuturesFundingRateHistory()GETcontract/public/funding-rate-history
getFuturesLeverageBracket()GETcontract/public/leverage-bracket
getFuturesAccountAssets()🔐GETcontract/private/assets-detail
getFuturesTradeFeeRate()🔐GETcontract/private/trade-fee-rate
getFuturesAccountOrder()🔐GETcontract/private/order
getFuturesAccountOrderHistory()🔐GETcontract/private/order-history
getFuturesAccountOpenOrders()🔐GETcontract/private/get-open-orders
getFuturesAccountPlanOrders()🔐GETcontract/private/current-plan-order
getFuturesAccountPositions()🔐GETcontract/private/position
getFuturesAccountPositionsV2()🔐GETcontract/private/position-v2
getPositionRiskDetails()🔐GETcontract/private/position-risk
getFuturesAccountTrades()🔐GETcontract/private/trades
getFuturesAccountTransactionHistory()🔐GETcontract/private/transaction-history
getFuturesAutoRepayment()🔐GETcontract/private/auto_repayment
getFuturesCrossCollateralInterestLog()🔐GETcontract/private/cross_collateral/interest_log
getFuturesTransfers()🔐GETaccount/v1/transfer-contract-list
submitFuturesOrder()🔐POSTcontract/private/submit-order
updateFuturesLimitOrder()🔐POSTcontract/private/modify-limit-order
cancelFuturesOrder()🔐POSTcontract/private/cancel-order
cancelAllFuturesOrders()🔐POSTcontract/private/cancel-orders
cancelAllFuturesOrdersAfter()🔐POSTcontract/private/cancel-all-after
submitFuturesPlanOrder()🔐POSTcontract/private/submit-plan-order
cancelFuturesPlanOrder()🔐POSTcontract/private/cancel-plan-order
submitFuturesTransfer()🔐POSTaccount/v1/transfer-contract
setFuturesLeverage()🔐POSTcontract/private/submit-leverage
submitFuturesTPSLOrder()🔐POSTcontract/private/submit-tp-sl-order
updateFuturesPlanOrder()🔐POSTcontract/private/modify-plan-order
updateFuturesPresetPlanOrder()🔐POSTcontract/private/modify-preset-plan-order
updateFuturesTPSLOrder()🔐POSTcontract/private/modify-tp-sl-order
submitFuturesTrailOrder()🔐POSTcontract/private/submit-trail-order
cancelFuturesTrailOrder()🔐POSTcontract/private/cancel-trail-order
setPositionMode()🔐POSTcontract/private/set-position-mode
getPositionMode()🔐GETcontract/private/get-position-mode
submitFuturesSubToMainTransferFromMain()🔐POSTaccount/contract/sub-account/main/v1/sub-to-main
submitFuturesMainToSubTransferFromMain()🔐POSTaccount/contract/sub-account/main/v1/main-to-sub
submitFuturesSubToMainSubFromSub()🔐POSTaccount/contract/sub-account/sub/v1/sub-to-main
getFuturesSubWallet()🔐GETaccount/contract/sub-account/main/v1/wallet
getFuturesSubTransfers()🔐GETaccount/contract/sub-account/main/v1/transfer-list
getFuturesSubTransferHistory()🔐GETaccount/contract/sub-account/v1/transfer-history
getFuturesAffiliateRebates()🔐GETcontract/private/affiliate/rebate-list
getFuturesAffiliateTrades()🔐GETcontract/private/affiliate/trade-list
getFuturesAffiliateRebateUser()🔐GETcontract/private/affiliate/rebate-user
getFuturesAffiliateRebateInviteUser()🔐GETcontract/private/affiliate/rebate-inviteUser
getFuturesAffiliateRebateApi()🔐GETcontract/private/affiliate/rebate-api
getFuturesAffiliateDepositWithdrawalList()🔐GETcontract/private/affiliate/deposit-withdrawal-list
submitFuturesSimulatedClaim()🔐POSTcontract/private/claim

Source: View endpoint map source

BitMart JavaScript FAQ

What does the BitMart JavaScript SDK cover?

BitMart supports Spot, Margin, Futures, and WebSockets workflows. The JavaScript guide covers the main REST and WebSocket integration patterns.

How do I authenticate private BitMart API calls in JavaScript?

Install bitmart-api from npm & pass API credentials into the SDK client options, as shown in the BitMart JavaScript examples above. The SDK handles the exchange-specific signing requirements for private requests.

Does the BitMart JavaScript SDK help with WebSocket connection management?

Yes. Use the SDK WebSocket client for subscriptions, reconnect handling, and stream lifecycle management instead of building raw socket flows yourself.

Where should I start on the BitMart JavaScript page: REST or WebSocket?

Start with the REST quick start for installation, authentication, and request and response flows. Move to the WebSocket example when you need streaming market or account updates.

Direct Example Files

Open the example files below if you want the clearest general-purpose starting point for REST API, WebSocket, and authentication workflows in plain JavaScript.

Reference Links