Registry / devops / binance-websocket-api-node

binance-websocket-api-node

JSON →
library1.0.11jsnpmunverified

A Node.js client for the Binance WebSocket API (WebSocket API, not WebSocket Streams). Version 1.0.11 is the current stable release. It supports both public endpoints (ping, time, exchangeInfo) and authenticated trading endpoints (order, cancel, account info) through the Binance WebSocket API. Unlike REST-based clients, this library uses WebSocket for lower-latency communication. Only spot trading is supported. The library is TypeScript-friendly with bundled type definitions and uses promises/async-await.

npm install binance-websocket-api-node
INSTALL
IMPORT
SIG · BINANCE-WEBSOCKET-
B
binance-websocket-api-node
devopsjavascriptv1.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

BinanceWebSocketApi
import BinanceWebSocketApi from 'binance-websocket-api-node'
const BinanceWebSocketApi = require('binance-websocket-api-node')
Default ESM import. CommonJS require also works.
ClientOptions
import type { ClientOptions } from 'binance-websocket-api-node'
import { ClientOptions } from 'binance-websocket-api-node'
TypeScript type import, value-level import will cause runtime error.
client instance
const client = new BinanceWebSocketApi({ webSocket: require('ws') })
const client = new BinanceWebSocketApi()
webSocket option is mandatory; omitting it will cause connection failure.

Shows how to create an unauthenticated client, get server time, and fetch exchange info.

import webSocket from 'ws'; import BinanceWebSocketApi from 'binance-websocket-api-node'; const client = new BinanceWebSocketApi({ webSocket: webSocket, }); async function main() { try { const time = await client.time(); console.log('Server time:', time); const exchangeInfo = await client.exchangeInfo(); console.log('Exchange info:', exchangeInfo.symbols.length, 'symbols'); } catch (error) { console.error('Error:', error); } } main();
Debug
Known issues
gotchaThe webSocket option is required and must be the 'ws' library instance. Omitting it will throw an error.
fix
Always provide { webSocket: require('ws') } or { webSocket: WebSocket } (if using 'ws' with ESM).
affects: >=1.0.0
breakingThe library uses Binance WebSocket API (wss://ws-api.binance.com/ws-api/v3), not WebSocket Streams (wss://stream.binance.com:9443). Mixing them up will cause connection failures.
fix
Ensure you are using the correct endpoint. The library does not expose endpoint configuration.
affects: >=1.0.0
deprecatedThe user() method for WebSocket user data streams may be deprecated in future versions; check the library's documentation for updates.
fix
Use the userDataStream() method if available, or monitor the library for changes.
affects: >=1.0.0
gotchaOnly spot trading is supported. Futures or margin trading are not available.
fix
Use a different library for futures/margin trading (e.g., binance-api-node).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Invalid URL
Missing or invalid webSocket option (not a WebSocket constructor).
fix
Ensure you pass the 'ws' module (import WebSocket from 'ws') as the webSocket option.
Cannot find module 'ws'
The 'ws' package is not installed.
fix
Run 'npm install ws' or 'yarn add ws' to install the WebSocket dependency.
Error: APIError(code=-2015): Invalid API-key, IP, or permissions for action.
Invalid API key/secret or IP whitelist restriction.
fix
Verify API key and secret are correct, and ensure your IP is whitelisted in Binance API settings.
Upgrade
Version history
1.0.11latest on npm
Audit
Dependencies
wsrequiredWebSocket implementation required for communication with Binance WebSocket API
Agent activity
11 hits · last 30 days
node
10
Resources
binance-websocket-api-node — npm install binance-websocket-api-node · libregistry