{"id":13615,"library":"node-binance-api","title":"Binance API Client for Node.js","description":"The `node-binance-api` package provides a comprehensive client library for interacting with the Binance cryptocurrency exchange API from Node.js environments. It offers full coverage of Binance's Spot, Futures, and WebSocket APIs, enabling real-time market data streaming, order management, and account queries. The current stable version is 1.0.27, and the library maintains a relatively active release cadence, frequently pushing minor updates and bug fixes. Key differentiators include extensive API coverage, robust WebSocket support for various data streams, and built-in handling for common trading operations, making it suitable for developing automated trading bots and market analysis tools.","status":"active","version":"1.0.27","language":"javascript","source_language":"en","source_url":"https://github.com/ccxt/node-binance-api","tags":["javascript","binance","api","trading","crypto","typescript"],"install":[{"cmd":"npm install node-binance-api","lang":"bash","label":"npm"},{"cmd":"yarn add node-binance-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-binance-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The default export is a factory function that returns a Binance API client instance. Do not use 'new' with the imported module itself.","wrong":"import { Binance } from 'node-binance-api';\n// OR\nconst Binance = require('node-binance-api');\nconst binance = new Binance().options({ /* ... */ });","symbol":"Binance","correct":"import Binance from 'node-binance-api';\nconst binance = Binance().options({ /* ... */ });"},{"note":"WebSockets is a named export, used for direct access to WebSocket utilities if not using the main client instance.","wrong":"import WebSockets from 'node-binance-api';","symbol":"WebSockets","correct":"import { WebSockets } from 'node-binance-api';"},{"note":"For CommonJS, the require statement returns the factory function. Invoke it immediately or assign and then call to get the instance.","wrong":"const Binance = new require('node-binance-api')();","symbol":"require for CJS","correct":"const Binance = require('node-binance-api');\nconst binance = Binance().options({ /* ... */ });"}],"quickstart":{"code":"import Binance from 'node-binance-api';\n\nconst binance = Binance().options({\n  APIKEY: process.env.BINANCE_API_KEY ?? '',\n  APISECRET: process.env.BINANCE_API_SECRET ?? '',\n  useServerTime: true, // Recommended to sync time with Binance\n  recvWindow: 60000, // Set a higher recvWindow for potentially slow networks\n});\n\nasync function getMarketDataAndBalance() {\n  try {\n    console.log('Fetching market prices...');\n    const prices = await binance.prices();\n    console.log('Current BTCUSDT price:', prices.BTCUSDT);\n\n    if (binance.options.APIKEY && binance.options.APISECRET) {\n      console.log('\\nFetching account balances...');\n      const balances = await binance.balance();\n      console.log('Available USDT balance:', balances.USDT ? balances.USDT.available : 'N/A');\n      console.log('Available BTC balance:', balances.BTC ? balances.BTC.available : 'N/A');\n    } else {\n      console.log('\\nSkipping account balance check: API_KEY and/or API_SECRET not provided.');\n    }\n\n    console.log('\\nSubscribing to BTCUSDT KLine stream for 1 minute intervals...');\n    binance.websockets.chart(\"BTCUSDT\", \"1m\", (symbol, interval, chart) => {\n      const tick = binance.last(chart);\n      console.log(`[${new Date(tick.openTime).toLocaleTimeString()}] BTCUSDT 1m: Open ${tick.open}, High ${tick.high}, Low ${tick.low}, Close ${tick.close}`);\n    });\n\n  } catch (error) {\n    console.error('An error occurred:', error.message);\n  }\n}\n\ngetMarketDataAndBalance();","lang":"typescript","description":"This quickstart initializes the Binance API client using environment variables, fetches current market prices, retrieves account balances (if API keys are provided), and demonstrates a real-time WebSocket subscription for BTCUSDT 1-minute candlestick data."},"warnings":[{"fix":"Existing WebSocket implementations may need to be updated. Review the official documentation for `node-binance-api` and adapt WebSocket subscription calls to utilize the new `ws-api` methods or structures.","message":"The WebSocket subscription mechanism underwent changes in v1.0.21, updating to use the `ws-api` for subscriptions.","severity":"breaking","affected_versions":">=1.0.21"},{"fix":"Implement robust rate-limiting strategies within your application to manage request frequency. Consult Binance's official API documentation for the most current rate limit details and best practices.","message":"Binance API rate limits are strictly enforced across all endpoints (REST and WebSockets). Exceeding these limits will result in temporary IP bans, HTTP 429 errors, or account restrictions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use secure methods for managing credentials, such as environment variables (e.g., `process.env.BINANCE_API_KEY`), dedicated configuration management tools, or secret management services. Never expose keys publicly.","message":"API keys and secrets provide full access to your Binance account. Hardcoding them or committing them to version control (e.g., Git) is a significant security vulnerability.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call the imported module as a function to get the client instance: `const binance = Binance().options({...});` rather than `const binance = new Binance().options({...});`.","message":"The `node-binance-api` module's default export is a factory function, not a class constructor. Attempting to instantiate it with `new` on the module itself will lead to a `TypeError`.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use methods like `binance.setFuturesEndpoint()` and verify that the API key provided in `binance.options()` has the necessary permissions enabled for Futures trading on your Binance account.","message":"When interacting with Binance Futures APIs, ensure you configure the client with the correct endpoint and use API keys that have Futures trading permissions.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.27':57 'account':50 'activ':64 'analysi':106 'api':2,10,24,39,78,110 'autom':101 'binanc':1,9,21,33,109 'bot':103 'bug':72 'built':89 'built-in':88 'cadenc':66 'client':3,15 'common':93 'comprehens':14 'coverag':31,79 'crypto':112 'cryptocurr':22 'current':53 'data':45,85 'develop':100 'differenti':75 'enabl':40 'environ':27 'exchang':23 'extens':77 'fix':73 'frequent':67 'full':30 'futur':36 'handl':91 'includ':76 'interact':18 'javascript':108 'key':74 'librari':16,60 'maintain':61 'make':96 'manag':48 'market':44,105 'minor':69 'node':8 'node-binance-api':7 'node.js':5,26 'offer':29 'oper':95 'order':47 'packag':11 'provid':12 'push':68 'queri':51 'real':42 'real-tim':41 'relat':63 'releas':65 'robust':80 'spot':35 'stabl':54 'stream':46,86 'suitabl':98 'support':82 'time':43 'tool':107 'trade':94,102,111 'typescript':113 'updat':70 'various':84 'version':55 'websocket':38,81","created_at":"2026-04-20T01:55:25.232760+00:00","updated_at":"2026-04-20T01:55:25.232760+00:00","problems":[{"fix":"Remove the `new` keyword: `const binance = Binance().options({...});`.","cause":"The main export of `node-binance-api` is a factory function, not a class. You are trying to instantiate it using `new`.","error":"TypeError: Binance is not a constructor"},{"fix":"Ensure your server's time is synchronized using NTP. You can also try setting `useServerTime: true` in the `binance.options()` to have the library attempt to use Binance's server time for requests.","cause":"Your local system's clock is significantly out of sync with Binance's servers.","error":"Error: -1021: Timestamp for this request was 1000ms ahead of the server's time."},{"fix":"Double-check your API_KEY and API_SECRET. Verify on the Binance website that the API key is active, has the required permissions (e.g., Spot Trading, Futures Trading, Read), and that your server's IP address is whitelisted if IP restrictions are enabled.","cause":"The provided API key or secret is incorrect, expired, lacks necessary permissions for the requested action, or your IP address is not whitelisted.","error":"Error: -2015: Invalid API-KEY, IP, or permissions for action."},{"fix":"Ensure your API key has WebSocket permissions. For user data streams, verify that you have obtained a valid `listenKey` and it has not expired. Refresh the `listenKey` regularly (e.g., every 30-60 minutes).","cause":"Attempting to connect to a user-specific WebSocket stream (e.g., user data stream) with an invalid or unauthorized API key/signature, or an expired listen key.","error":"WebSocket connection failed: 401 Unauthorized"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/ccxt/node-binance-api","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/node-binance-api","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","communication"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}