{"id":12886,"library":"binance-api-node","title":"Binance API Node.js Wrapper","description":"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.","status":"active","version":"0.13.9","language":"javascript","source_language":"en","source_url":"https://github.com/ccxt/binance-api-node","tags":["javascript","typescript"],"install":[{"cmd":"npm install binance-api-node","lang":"bash","label":"npm"},{"cmd":"yarn add binance-api-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add binance-api-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Standard ESM import for the default export. Recommended for modern Node.js and browser environments with module support.","symbol":"Binance","correct":"import Binance from 'binance-api-node'"},{"note":"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.","wrong":"const Binance = require('binance-api-node')","symbol":"Binance","correct":"const Binance = require('binance-api-node').default"},{"note":"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.","symbol":"WebSocket types","correct":"import type { Depth, Ticker } from 'binance-api-node'"}],"quickstart":{"code":"import Binance from 'binance-api-node';\n\nconst apiKey = process.env.BINANCE_API_KEY ?? '';\nconst apiSecret = process.env.BINANCE_API_SECRET ?? '';\nconst testnetMode = process.env.BINANCE_TESTNET === 'true';\n\nconst client = Binance({\n  apiKey: apiKey,\n  apiSecret: apiSecret,\n  testnet: testnetMode,\n  // Optional: Provide a custom getTime function if you encounter timestamp issues\n  // getTime: () => Date.now() + 1000 // Example: account for clock skew\n});\n\nasync function getBinanceTime() {\n  try {\n    const serverTime = await client.time();\n    console.log('Binance Server Time:', serverTime);\n\n    if (apiKey && apiSecret) {\n      // Example of an authenticated call\n      const accountInfo = await client.accountInfo();\n      console.log('Account Info Balances:', accountInfo.balances.filter(b => parseFloat(b.free) > 0));\n    } else {\n      console.log('API Key and Secret not provided. Skipping authenticated calls.');\n    }\n\n    // Example of a public WebSocket stream\n    client.ws.trades('BNBUSDT', trade => {\n      console.log('Latest BNBUSDT Trade:', trade);\n      // In a real application, you might want to unsubscribe after a while\n      // client.ws.trades.close('BNBUSDT');\n    });\n\n  } catch (error) {\n    console.error('Error interacting with Binance API:', error);\n  }\n}\n\ngetBinanceTime();","lang":"typescript","description":"Initializes a Binance API client, fetches server time, retrieves account information (if authenticated), and subscribes to a public trade WebSocket stream for BNBUSDT."},"warnings":[{"fix":"Replace `client.ws.allTickers(...)` with `client.ws.miniTicker(...)` in your application logic.","message":"The `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.","severity":"breaking","affected_versions":">=0.13.4"},{"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.","message":"WebSocket 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.","severity":"breaking","affected_versions":">=0.13.9"},{"fix":"Ensure your runtime environment supports Promises (Node.js 8+ or recent browsers). For extremely old environments, consider adding a polyfill like `es6-promise`.","message":"The 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.","severity":"gotcha","affected_versions":"<0.12.0 (but still relevant for very old runtimes)"},{"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.","message":"Proxy 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.","severity":"gotcha","affected_versions":">=0.13.2"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `const Binance = require('binance-api-node').default;` for CommonJS imports.","cause":"Attempting to use `require('binance-api-node')` directly in CommonJS instead of accessing the default export.","error":"TypeError: Binance is not a constructor"},{"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 })`.","cause":"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.","error":"Error: Timestamp for this request is outside of the recvWindow."},{"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.","cause":"Incorrectly formatted or missing `apiKey` when initializing the client or making authenticated requests.","error":"Error: API-key format invalid."},{"fix":"Update your code to use `client.ws.miniTicker` instead, as `allTickers` was deprecated.","cause":"Attempting to use the deprecated `allTickers` WebSocket stream method after upgrading to a version where it has been removed or replaced.","error":"TypeError: client.ws.allTickers is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}