Binance JavaScript SDK
Build with the Binance 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 Binance SDK:
- Spot
- Futures
- Margin
- WebSockets
- WebSocket API
- WebSocket clients with:
- Built-in heartbeats.
- Automatic reconnection.
- Automatic reauthentication and resubscribe where the exchange supports it.
- Promise-wrapped WebSocket API commands you can await like a REST API.
- 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 Binance SDK
# Via your favourite package manager, e.g. npm:
npm install binance
# or pnpm:
pnpm install binance
# or yarn:
yarn add binanceQuickstart Examples with the Binance 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.
Quickstart snippets are currently unavailable for this SDK and language combination.
Binance API JavaScript Tutorial
A practical JavaScript guide to using binance across Binance Spot, margin, USD-M Futures, COIN-M Futures, Portfolio Margin, public streams, user data, WebSocket API commands, and production rollout checks.
Your app / service
bot, dashboard, worker
binance
MainClient, USDMClient, WebsocketAPIClient
Binance APIs
Spot, Futures, Portfolio Margin, streams, WebSocket API
Common Binance implementation tasks
Start from the behavior you need, not just from REST or WebSocket as a transport. Market-data driven systems should be event driven. Backfill via the REST API once and let WebSockets passively stream new data to you, as it becomes available.
Public spot trades stream
Use the current public WebSocket example when you need the simplest verified Binance market-data stream.
Open public stream exampleCandle-Close Pipeline with Binance APIs & WebSockets
Use the task guide for REST API backfill, kline WebSockets, buffering, replay, final-candle execution, reconnect resync, and shutdown while the full canonical repo example is still a repo-side task.
Open candle pipeline guidePosition Management with Binance APIs & WebSockets
Use the private-account guide for REST API hydration, user-data streams, DCA/TP/SL dry-run intents, SDK-prefixed client IDs, structured errors, and reconnect reconciliation.
Open position manager guideBackfill endpoint lookup
Use the endpoint reference to verify the current REST API candle method, request shape, response fields, and product-specific naming before coding.
Open endpoint referenceReconnect-safe consumer
Tell the agent to treat transport reconnect as separate from application correctness, then resync through the REST API before re-enabling event-driven workflows.
Open agent guidanceFor coding agents
Give these files to an agent before implementation so it can find the package, examples, task guidance, and safety rules from the normal SDK-page flow.
AI prompt framework
Prompt generator and task recipes for exchange API projects.
llms.txt
Compact discovery file for agents choosing where to start.
llms-full.txt
Full route and implementation guidance index for machine readers.
SDK catalog
Machine-readable package, docs, examples, and task guidance.
Agent skill
Reusable workflow rules for coding agents using exchange APIs.
Endpoint Function Reference
Binance JavaScript FAQ
What does the Binance JavaScript SDK cover?
Binance supports Spot, Futures, Margin, WebSockets, and WebSocket API workflows. The JavaScript guide covers the main REST and WebSocket integration patterns.
How do I authenticate private Binance API calls in JavaScript?
Install binance from npm & pass API credentials into the SDK client options, as shown in the Binance JavaScript examples above. The SDK handles the exchange-specific signing requirements for private requests.
Does the Binance 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.
When should I use the Binance WebSocket API instead of REST?
Use REST for standard request and response workflows such as account queries and order management. Use the WebSocket API flow when you want persistent low-latency interactions over a connected session.
Direct Example Files
Open the example files below for JavaScript and TypeScript-compatible request, authentication, WebSocket, and Node.js service patterns.