Binance API SDK
binance provides JavaScript and TypeScript clients for Binance REST and WebSocket APIs, covering market data, account queries and trading.
Build trading bots and automate your Binance strategies in Node.js, or use real-time market data in a dashboard. Start with a public price request, then add authentication and order handling for your trading workflow.
JavaScript & TypeScript · v3.6.11 · MIT license
Installation
TypeScript definitions are included.
npm install binancepnpm add binanceyarn add binanceChoose your setup
Start with the tools you already use. Each guide includes a complete project, setup commands, expected output and cleanup where applicable.
- Node.js / JavaScript: run plain JavaScript with
importorrequire, without a TypeScript compiler. - Node.js / TypeScript: type-check and compile a Node.js price and subscription script.
- React: display live prices in a React component with effect cleanup, using Vite.
- Vite (plain JavaScript): display prices in a browser page without React.
- Next.js: return a price from a Node.js server Route Handler.
- React Native / Expo: display prices and stop subscriptions on iOS and Android.
- Bun and Deno: run a price and WebSocket script in your chosen runtime.
Each guide includes a downloadable starter generated from the maintained examples and runtime configuration. Runtime compatibility records tested versions and scope.
Usage
This request reads the BTCUSDT Spot price and requires no API key.
import { MainClient } from 'binance';
async function main() {
const client = new MainClient();
const result = await client.getSymbolPriceTicker({ symbol: 'BTCUSDT' });
if (Array.isArray(result)) throw new Error('Expected a single-symbol ticker.');
console.log('BTCUSDT last price:', result.price);
}
main().catch((error) => {
console.error(error instanceof Error ? error.message : 'Request failed. See the troubleshooting guide.');
process.exitCode = 1;
});The example prints the BTCUSDT price. See the Node.js quickstart to run it.
Choose a client
| Client | Purpose |
|---|---|
MainClient | Spot and related account endpoints over HTTP. |
USDMClient | USD-M futures endpoints. |
CoinMClient | COIN-M futures endpoints. |
PortfolioClient | Portfolio Margin endpoints. |
WebsocketClient | Market and account streams, with raw message events and optional formatted events. |
WebsocketAPIClient | Supported awaitable operations over Binance WebSocket APIs. |
Next steps
- Run your first request.
- Read an order book.
- Subscribe to live market updates.
- Configure authentication.
- Prepare for production or troubleshoot a problem.
- Browse the complete API reference.
For a longer walkthrough, see the Binance JavaScript tutorial on Siebly.io.