Node.js & JavaScript SDK for Binance REST APIs & WebSockets
[!TIP] Upcoming change: As part of the Siebly.io brand, this SDK is now hosted under our Siebly.io GitHub organisation. The migration is seamless and requires no user changes.
Updated & performant JavaScript & Node.js SDK for the Binance REST APIs and WebSockets:
- Professional, robust & performant Binance SDK with leading trading volume in production (livenet).
- Extensive integration with Binance REST APIs, WebSockets & WebSocket APIs.
- Complete TypeScript support (with type declarations for all API requests & responses).
- Supports Binance REST APIs for Binance Spot, Margin, Isolated Margin, Options, USDM & CoinM Futures.
- Strongly typed requests and responses.
- Automated end-to-end tests on most API calls, ensuring no breaking changes are released to npm.
- Actively maintained with a modern, promise-driven interface.
- Support for all authentication mechanisms available on Binance:
- HMAC
- RSA
- Ed25519 (required for WS API login, else each request is signed).
- Passing a private key as a secret will automatically detect whether to switch to RSA or Ed25519 authentication.
- Supports WebSockets for all available product groups on Binance including Spot, Margin, Isolated Margin, Portfolio, Options, USDM & CoinM Futures.
- Event driven messaging.
- Smart WebSocket persistence
- Automatically handle silent WebSocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
- Automatically handle listenKey persistence and expiration/refresh.
- Emit
reconnectedevent when dropped connection is restored.
- Strongly typed on most WebSocket events, with typeguards available for TypeScript users.
- Optional:
- Automatic beautification of WebSocket events (from one-letter keys to descriptive words, and strings with floats to numbers).
- Automatic beautification of REST responses (parsing numbers in strings to numbers).
- Supports WebSocket API on all available product groups, including Spot & Futures:
- Use the WebsocketClient's event-driven
sendWSAPIRequest()method, or; - Use the WebsocketAPIClient for a REST-like experience. Use the WebSocket API like a REST API! See examples/ws-api-client.ts for a demonstration.
- Use the WebsocketClient's event-driven
- Heavy automated end-to-end testing with real API calls.
- End-to-end testing before any release.
- Real API calls in e2e tests.
- Proxy support via axios integration.
- Active community support & collaboration in telegram: Node.js Algo Traders.
- QuickStart Guide: Binance JavaScript QuickStart Guide
- Binance JavaScript Tutorial: Binance JavaScript REST API & WebSocket Tutorial
Table of Contents
- Installation
- Examples
- Issues & Discussion
- Related Projects
- Documentation Links
- Usage
- LLMs & AI
- Contributions & Thanks
Installation
npm install binance --save
Examples
Refer to the examples folder for implementation demos.
Issues & Discussion
- Issues? Check the issues tab.
- Discuss & collaborate with other node devs? Join our Node.js Algo Traders engineering community on telegram.
- Questions about Binance APIs & WebSockets? Ask in the official Binance API group on telegram.
- Follow our announcement channel for real-time updates on X/Twitter
Related Projects
Check out our JavaScript/TypeScript/Node.js SDKs & Projects:
- Visit our website: https://Siebly.io
- Try our REST API & WebSocket SDKs published on npmjs:
- Bybit JavaScript SDK: bybit-api
- Kraken JavaScript SDK: @siebly/kraken-api
- OKX JavaScript SDK: okx-api
- Binance JavaScript SDK: binance
- Gate (gate.com) JavaScript SDK: gateio-api
- Bitget JavaScript SDK: bitget-api
- Kucoin JavaScript SDK: kucoin-api
- Coinbase JavaScript SDK: coinbase-api
- HTX JavaScript SDK: @siebly/htx-api
- Try my misc utilities:
- Check out my examples:
Documentation
Most methods accept JS objects. These can be populated using parameters specified by Binance's API documentation.
- Binance API Documentation
- Find all products here
- REST Endpoint Function List
- TSDoc Documentation (autogenerated using typedoc)
Structure
This project uses typescript. Resources are stored in 3 key structures:
- src - the whole connector written in typescript
- lib - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
- dist - the packed bundle of the project for use in browser environments.
Usage
Create API credentials at Binance
- Livenet
- Testnet.
- Testnet Futures.
- Demo Trading - Uses real market data with simulated trading.
Demo Trading vs Testnet
Binance offers t