Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/binance/llms.txt

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

MainClient is the primary REST client for Binance’s core product suite. It targets the api*.binance.com family of subdomains and provides typed methods for Spot trading, Cross and Isolated Margin, Wallet operations, Convert, Simple Earn, Auto-Invest, Dual Investment, Staking, Mining, Crypto Loans, VIP Loans, NFTs, C2C, sub-account management, and more. If you are working with Spot or Margin markets — or any non-futures product — MainClient is the class you need.

Installation

1

Install the package

npm install binance
2

Import MainClient

import { MainClient } from 'binance';
// CommonJS: const { MainClient } = require('binance');
3

Instantiate the client

const client = new MainClient({
  api_key: process.env.BINANCE_API_KEY,
  api_secret: process.env.BINANCE_API_SECRET,
});

Constructor Options

The MainClient constructor accepts an optional RestClientOptions object followed by an optional Axios request-config for low-level HTTP customisation.
const client = new MainClient(
  restClientOptions,  // RestClientOptions (optional)
  requestOptions,     // AxiosRequestConfig (optional)
);
api_key
string
Your Binance API key. Required for all authenticated (private) endpoints.
api_secret
string
Your Binance API secret. Required for HMAC-signed requests. Pass an RSA or Ed25519 private key here — the SDK detects the key type automatically.
beautifyResponses
boolean
default:"false"
When true, the SDK parses numeric strings in responses into JavaScript numbers for well-known fields.
testnet
boolean
default:"false"
Routes requests to https://testnet.binance.vision. Useful for development and automated testing.
demoTrading
boolean
default:"false"
Routes requests to Binance’s Demo Trading environment. This uses real market data with simulated order execution — ideal for strategy testing.
Prefer demoTrading: true over testnet: true for strategy validation. The Demo Trading environment mirrors live market data, while the Testnet uses simulated prices that diverge significantly from real markets.

Method Categories

Market Data

Public endpoints — no API key required.
MethodEndpointDescription
testConnectivity()GET api/v3/pingTest connectivity to the REST API
getExchangeInfo(params?)GET api/v3/exchangeInfoExchange trading rules and symbol info
getOrderBook(params)GET api/v3/depthOrder book depth for a symbol
getRecentTrades(params)GET api/v3/tradesRecent trades list
getAggregateTrades(params)GET api/v3/aggTradesCompressed aggregate trade list
getKlines(params)GET api/v3/klinesKline/candlestick data
getUIKlines(params)GET api/v3/uiKlinesUI-optimised kline data
getAvgPrice(params)GET api/v3/avgPriceCurrent average price
get24hrChangeStatistics(params?)GET api/v3/ticker/24hr24-hour rolling window statistics
getSymbolPriceTicker(params?)GET api/v3/ticker/priceLatest price for a symbol or all symbols
getSymbolOrderBookTicker(params?)GET api/v3/ticker/bookTickerBest bid/ask price and quantity
getRollingWindowTicker(params)GET api/v3/tickerRolling window price change statistics
getTradingDayTicker(params)GET api/v3/ticker/tradingDayTrading day price change statistics

Order Management

Authenticated endpoints — require api_key and api_secret.
MethodEndpointDescription
submitNewOrder(params)POST api/v3/orderPlace a new Spot order
testNewOrder(params)POST api/v3/order/testTest order placement without execution
getOrder(params)GET api/v3/orderQuery status of an order
cancelOrder(params)DELETE api/v3/orderCancel an active order
cancelAllSymbolOrders(params)DELETE api/v3/openOrdersCancel all open orders for a symbol
replaceOrder(params)POST api/v3/order/cancelReplaceCancel and replace an order atomically
getOpenOrders(params?)GET api/v3/openOrdersGet all open orders
getAllOrders(params)GET api/v3/allOrdersFull order history for a symbol

Order Lists (OCO / OTO / OTOCO)

MethodEndpointDescription
submitNewOCO(params)POST api/v3/order/ocoPlace an OCO (One-Cancels-Other) order
submitNewOrderList(params)POST api/v3/orderList/ocoPlace a new OCO order list
submitNewOrderListOTO(params)POST api/v3/orderList/otoPlace an OTO (One-Triggers-Other) order list
submitNewOrderListOTOCO(params)POST api/v3/orderList/otocoPlace an OTOCO order list
submitNewOrderListOPO(params)POST api/v3/orderList/opoPlace an OPO order list
submitNewOrderListOPOCO(params)POST api/v3/orderList/opocoPlace an OPOCO order list
cancelOCO(params)DELETE api/v3/orderListCancel an order list
getOCO(params)GET api/v3/orderListQuery a specific order list
getAllOCO(params?)GET api/v3/allOrderListAll order lists for the account
getAllOpenOCO()GET api/v3/openOrderListAll open order lists

Account

MethodEndpointDescription
getAccountInformation()GET api/v3/accountAccount balances and permissions
getAccountTradeList(params)GET api/v3/myTradesTrade history for a symbol
getCommissionRates(params)GET api/v3/account/commissionCommission rates for a symbol
getBalances()GET sapi/v1/capital/config/getallAll coin balances with wallet info

Margin Trading

MethodEndpointDescription
getCrossMarginCollateralRatio()GET sapi/v1/margin/crossMarginCollateralRatioCross-margin collateral ratios
queryCrossMarginAccountDetails()GET sapi/v1/margin/accountCross-margin account details
submitMarginAccountBorrowRepay(params)POST sapi/v1/margin/borrow-repayBorrow or repay margin assets
getMarginAccountBorrowRepayRecords(params)GET sapi/v1/margin/borrow-repayBorrow/repay history
marginAccountNewOrder(params)POST sapi/v1/margin/orderPlace a margin order
marginAccountCancelOrder(params)DELETE sapi/v1/margin/orderCancel a margin order
getIsolatedMarginAccountInfo(params?)GET sapi/v1/margin/isolated/accountIsolated margin account details

Code Examples

import { MainClient } from 'binance';

const client = new MainClient();

async function fetchMarketData() {
  // Single-symbol ticker
  const ticker = await client.get24hrChangeStatistics({ symbol: 'BTCUSDT' });
  console.log('24hr ticker:', ticker);

  // All tickers at once
  const allTickers = await client.get24hrChangeStatistics();
  console.log(`Fetched ${allTickers.length} tickers`);

  // Exchange info (trading rules, filters, etc.)
  const info = await client.getExchangeInfo({ symbol: 'BTCUSDT' });
  console.log('Exchange info:', info.symbols[0].filters);

  // Recent klines (1-minute candles)
  const klines = await client.getKlines({
    symbol: 'BTCUSDT',
    interval: '1m',
    limit: 10,
  });
  console.log('Latest close:', klines[klines.length - 1][4]);
}

fetchMarketData().catch(console.error);

Product Coverage

MainClient covers an exceptionally wide range of Binance product groups. The table below summarises the main API families available.

Spot Trading

Order placement, cancellation, and history. Supports MARKET, LIMIT, STOP_LOSS, TAKE_PROFIT, and advanced order list types (OCO, OTO, OTOCO, OPO, OPOCO).

Margin Trading

Cross and isolated margin accounts, borrow/repay, margin orders, forced liquidation records, and interest history.

Wallet & Transfers

Deposit/withdrawal addresses and history, dust conversion, universal transfers, sub-account management, and fiat operations.

Convert & Earn

Convert API for instant swaps, Simple Earn flexible/locked products, Auto-Invest plans, Dual Investment, and Staking.

Crypto Loans

Borrow, repay, LTV adjustments, and liquidation history for both standard and flexible crypto loans. VIP Loan endpoints included.

Mining & NFTs

Mining account stats, hashrate resale, mining earnings, plus NFT asset/deposit/withdrawal history.
For USD-M Futures, use USDMClient. For COIN-M Futures, use CoinMClient. For Portfolio Margin, use PortfolioClient.

Full Endpoint Map

The complete list of all MainClient methods mapped to their exact API endpoints is maintained in the repository: REST Endpoint Function List →

Build docs developers (and LLMs) love