SDK guide
JavaScript
REST API + WebSocket

BitMart JavaScript SDK

Build with the BitMart REST API & WebSockets with our JavaScript SDK, TypeScript-first package declarations, and Node.js-compatible runtime patterns. Discover installation, common examples, a detailed endpoint-to-function map, and the REST API/WebSocket patterns shared across our Siebly SDK family.

Use the same TypeScript-first REST API and WebSocket clients from plain JavaScript or TypeScript in Node.js-compatible runtimes.

Package surfaces

Explore the following API capabilities are covered by our BitMart SDK:

  • Spot
  • Margin
  • Futures
  • WebSockets
  • WebSocket clients with:
    • Built-in heartbeats.
    • Automatic reconnection.
    • Automatic reauthentication and resubscribe where the exchange supports it.
  • Typed requests and responses for Node.js, JavaScript, and TypeScript IDEs.
  • Framework-neutral JavaScript snippets that stay approachable in Node.js-compatible runtimes.
  • TypeScript-first package declarations for stricter services, shared libraries, and editor-assisted integrations.

Install BitMart SDK

# Via your favourite package manager, e.g. npm:
npm install bitmart-api
# or pnpm:
pnpm install bitmart-api
# or yarn:
yarn add bitmart-api

Quickstart Examples with the BitMart JavaScript SDK

Get started with just a few lines of JavaScript. TypeScript, while not required, is absolutely recommended. TypeScript declarations are included with all our SDKs and provide convenient definitions on request & response fields, WebSocket payloads, and generally safer integrations.

WebSocket API is not currently available for BitMart.

REST 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.

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();

Common BitMart implementation tasks

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
getAccountInfoV1()🔐GETuapi-key/v1/account/info
submitAccountTransferV1()🔐POSTaccount/v1/transfer
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
getEarnAccountPosition()🔐GETnewearn/cloud/v1/earn
getFlexibleSavingProducts()🔐GETnewearn/cloud/v1/saving/product
subscribeFlexibleSaving()🔐POSTnewearn/cloud/v1/saving/subscribe
redeemFlexibleSaving()🔐POSTnewearn/cloud/v1/saving/redeem
getFlexibleSavingPositions()🔐GETnewearn/cloud/v1/saving/earn
getFlexibleSavingHistory()🔐GETnewearn/cloud/v1/saving/record
getFixedSavingProducts()🔐GETnewearn/cloud/v1/saving/fixed/product
subscribeFixedSaving()🔐POSTnewearn/cloud/v1/saving/fixed/subscribe
getFixedSavingPositions()🔐GETnewearn/cloud/v1/saving/fixed/earn
getFixedSavingHistory()🔐GETnewearn/cloud/v1/saving/fixed/record
redeemFixedSavingEarly()🔐POSTnewearn/cloud/v1/saving/fixed/redeem
updateFixedSavingAutoReinvest()🔐POSTnewearn/cloud/v1/saving/fixed/subscribe/operate
setAutoSavingBatch()🔐POSTnewearn/cloud/v1/saving/subscribe/batch/operate
getAutoSavingBatchStatus()🔐GETnewearn/cloud/v1/saving/subscribe/batch
setFlexibleSavingAutoSubscribe()🔐POSTnewearn/cloud/v1/saving/subscribe/operate
getFlexibleSavingAutoSubscribeStatus()🔐GETnewearn/cloud/v1/saving/subscribe/status
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
getFuturesFundingRateV2()GETcontract/public/funding-rate-v2
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
closeAllFuturesPositions()🔐POSTcontract/private/close-all-position
submitFuturesPlanOrder()🔐POSTcontract/private/submit-plan-order
cancelFuturesPlanOrder()🔐POSTcontract/private/cancel-plan-order
submitFuturesTransfer()🔐POSTaccount/v1/transfer-contract
submitFuturesFundingAccountTransfer()🔐POSTcontract/private/account/v1/transfer
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
getFuturesAffiliateInviteCheck()🔐GETcontract/private/affiliate/invite-check
getFuturesAffiliateCustomerInfo()🔐GETcontract/private/affiliate/aff-customer-info
getFuturesAffiliateRebateInviteUser()🔐GETcontract/private/affiliate/rebate-inviteUser
getFuturesAffiliateRebateApi()🔐GETcontract/private/affiliate/rebate-api
getFuturesAffiliateDepositWithdrawalList()🔐GETcontract/private/affiliate/deposit-withdrawal-list
submitFuturesSimulatedClaim()🔐POSTcontract/private/claim
View endpoint map sourceShowing the available endpoint reference map.

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 for JavaScript and TypeScript-compatible request, authentication, WebSocket, and Node.js service patterns.

Continue with implementation resources

Subscribe on Substack

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