Registry / http-networking / binance-api-node

binance-api-node

JSON →
library0.13.9jsnpmunverified

binance-api-node is a comprehensive API wrapper for the Binance cryptocurrency exchange, designed for both Node.js and browser environments. The current stable version is 0.13.9, with frequent patch releases indicating active maintenance and continuous feature development. It leverages Promises for asynchronous operations, supporting both REST API calls and WebSocket streams. Key differentiators include built-in support for RSA/ECDSA key types, proxy configuration for Node.js environments, and explicit compatibility with Binance's newer Algo service. It differentiates itself by offering a unified interface for various Binance products (Spot, Margin, Futures) and providing TypeScript definitions out of the box, which is crucial for modern JavaScript development.

npm install binance-api-node
INSTALL
IMPORT
SIG · BINANCE-API-NODE
B
binance-api-node
http-networkingjavascriptv0.13.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

Binance
import Binance from 'binance-api-node'
Standard ESM import for the default export. Recommended for modern Node.js and browser environments with module support.
Binance
const Binance = require('binance-api-node').default
const Binance = require('binance-api-node')
For CommonJS environments (older Node.js projects or specific build setups), the '.default' property is necessary to access the main client constructor due to how ESM default exports are handled when transpiled or consumed in CJS.
WebSocket types
import type { Depth, Ticker } from 'binance-api-node'
The library ships with TypeScript types. Specific types for WebSocket data streams (e.g., `Depth`, `Ticker`) and other API responses can be imported for type safety, especially useful since version 0.13.7 improved type exports.

Initializes a Binance API client, fetches server time, retrieves account information (if authenticated), and subscribes to a public trade WebSocket stream for BNBUSDT.

import Binance from 'binance-api-node'; const apiKey = process.env.BINANCE_API_KEY ?? ''; const apiSecret = process.env.BINANCE_API_SECRET ?? ''; const testnetMode = process.env.BINANCE_TESTNET === 'true'; const client = Binance({ apiKey: apiKey, apiSecret: apiSecret, testnet: testnetMode, // Optional: Provide a custom getTime function if you encounter timestamp issues // getTime: () => Date.now() + 1000 // Example: account for clock skew }); async function getBinanceTime() { try { const serverTime = await client.time(); console.log('Binance Server Time:', serverTime); if (apiKey && apiSecret) { // Example of an authenticated call const accountInfo = await client.accountInfo(); console.log('Account Info Balances:', accountInfo.balances.filter(b => parseFloat(b.free) > 0)); } else { console.log('API Key and Secret not provided. Skipping authenticated calls.'); } // Example of a public WebSocket stream client.ws.trades('BNBUSDT', trade => { console.log('Latest BNBUSDT Trade:', trade); // In a real application, you might want to unsubscribe after a while // client.ws.trades.close('BNBUSDT'); }); } catch (error) { console.error('Error interacting with Binance API:', error); } } getBinanceTime();
Debug
Known issues
breakingThe `allTickers` WebSocket stream has been deprecated by Binance and replaced with `miniTicker`. Users upgrading from older versions must update their code to use `miniTicker` instead of `allTickers` for fetching all ticker information, or they will experience connection issues or missing data.
fix
Replace `client.ws.allTickers(...)` with `client.ws.miniTicker(...)` in your application logic.
affects: >=0.13.4
breakingWebSocket URLs for USDⓈ-M futures were split into public/market/private categories in version 0.13.9. This change might affect how WebSocket connections are initiated for futures, potentially requiring adjustments to how specific streams are accessed or configured.
fix
Review the official Binance API documentation and the `binance-api-node` source for updated WebSocket endpoint usage specific to USDⓈ-M futures streams. You might need to specify the exact stream category when subscribing.
affects: >=0.13.9
gotchaThe library primarily uses Promises for asynchronous operations. While modern Node.js and browser environments natively support Promises, very old environments might require a Promise polyfill to function correctly.
fix
Ensure your runtime environment supports Promises (Node.js 8+ or recent browsers). For extremely old environments, consider adding a polyfill like `es6-promise`.
affects: <0.12.0 (but still relevant for very old runtimes)
gotchaProxy support is exclusively available for Node.js environments. Attempting to configure a proxy when using the library in a browser environment will have no effect or may lead to unexpected behavior, as browsers handle proxy settings via the operating system.
fix
Only use the `proxy` option when running `binance-api-node` in a Node.js application. For browser-based applications, configure proxy settings at the OS or browser level if needed.
affects: >=0.13.2
Errors
Common errors & fixes
TypeError: Binance is not a constructor
Attempting to use `require('binance-api-node')` directly in CommonJS instead of accessing the default export.
fix
Use `const Binance = require('binance-api-node').default;` for CommonJS imports.
Error: Timestamp for this request is outside of the recvWindow.
This error typically indicates a significant clock skew between your local system and Binance's servers, or an excessively small `recvWindow` parameter if manually set.
fix
Ensure your system's clock is accurately synchronized (e.g., with an NTP server). You can also provide a `getTime` function during client initialization to account for clock skew: `Binance({ apiKey, apiSecret, getTime: () => Date.now() + 1000 })`.
Error: API-key format invalid.
Incorrectly formatted or missing `apiKey` when initializing the client or making authenticated requests.
fix
Double-check that your `apiKey` and `apiSecret` are correctly copied from your Binance account and passed as strings during client initialization. Ensure no leading/trailing spaces.
TypeError: client.ws.allTickers is not a function
Attempting to use the deprecated `allTickers` WebSocket stream method after upgrading to a version where it has been removed or replaced.
fix
Update your code to use `client.ws.miniTicker` instead, as `allTickers` was deprecated.
Upgrade
Version history
0.13.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
binance-api-node — npm install binance-api-node · libregistry