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.

The binance npm package is a professional, production-grade Node.js and TypeScript SDK for the full Binance API surface. It handles request building, authentication, timestamp synchronization, WebSocket lifecycle management, and response parsing — so your code can stay focused on the trading logic you’re building. Whether you need Spot market data, authenticated Futures orders, or a persistent WebSocket stream, every Binance product group is covered by a dedicated, strongly typed client.

What the SDK covers

Binance exposes multiple distinct API families, each with its own endpoint prefix, subdomain, and account model. The SDK maps directly to those product groups:
Product groupREST clientCommon usage
Spot, Margin, Wallet, Convert, Earn, Sub-accountsMainClientSpot trading, account data, wallet flows, transfers, savings
USD-M Futures (fapi/)USDMClientUSDT/USDC-margined futures, positions, orders
COIN-M Futures (dapi/)CoinMClientCoin-margined futures, positions, orders
Portfolio Margin (papi/)PortfolioClientUnified margin account, UM/CM/margin orders
WebSocket streamsWebsocketClientPublic market data & private user data streams
WebSocket APIWebsocketAPIClientREST-like commands over persistent WebSocket connections

Key features

Full TypeScript support

Every request parameter and API response is strongly typed. Type declarations are bundled — no separate @types package required.

All auth mechanisms

HMAC, RSA, and Ed25519 are all supported. Pass a PEM private key as api_secret and the SDK auto-detects the key type.

Smart WebSocket persistence

Automatic heartbeats, listen-key refresh, reconnection, and topic resubscription. Emits reconnected so you can reconcile state via REST.

Response beautification

Enable beautifyResponses: true to parse known float-strings into numbers across REST responses and WebSocket events.

Demo & testnet support

Switch to Binance demo trading (real market data, simulated fills) or testnet with a single constructor option.

Browser bundle support

A webpack config is included to build a browser bundle. See the README for frontend usage instructions.

Installation

npm install binance
The package supports both ESM import and CommonJS require() out of the box.
The package ships a llms.txt file in its root. If you’re building with AI coding assistants, point your LLM at that file — it contains an AI-optimised index of every function and its parameters.

Exported clients at a glance

import {
  MainClient,           // Spot, Margin, Wallet, Convert, Earn, Sub-accounts
  USDMClient,           // USD-M Futures
  CoinMClient,          // COIN-M Futures
  PortfolioClient,      // Portfolio Margin
  WebsocketClient,      // Streaming subscriptions (public + user data)
  WebsocketAPIClient,   // Promise-based WebSocket API commands
  WebsocketClientLegacy, // Legacy WebSocket client (older connection model)
} from 'binance';
All six primary clients accept the same { api_key, api_secret } constructor shape. Public market data endpoints work without credentials — just omit the keys. WebsocketClientLegacy is also exported for projects that depend on the older WebSocket connection model.
New projects should use WebsocketClient rather than WebsocketClientLegacy. The legacy client is retained for backward compatibility.
API credentials are scoped per environment. Live, demo trading, Spot testnet, and Futures testnet credentials are separate. Never mix them in the same client instance.

Quickstart

Install the SDK, make your first public call, and place a test order in under 5 minutes.

Authentication

Configure HMAC, RSA, or Ed25519 auth and learn credential best practices.

GitHub repository

Source code, examples folder, and issue tracker.

npm package

Latest release, version history, and bundle size.

Binance API docs

Official Binance REST API and WebSocket documentation.

Endpoint function map

Full mapping of every Binance endpoint to its SDK method name.

Build docs developers (and LLMs) love