Binance API for Developers – Complete Guide

Binance API for developers guide

The Binance API is one of the most powerful and widely used trading APIs in the crypto industry. With over 270 million users and daily trading volumes exceeding $20 billion, Binance's API infrastructure enables developers to build trading bots, market data dashboards, arbitrage systems, and custom trading applications.

In this complete guide, I'll walk you through everything you need to know about the Binance API — from creating your first API key to building a trading bot with REST and WebSocket connections. Whether you're a beginner developer or an experienced trader looking to automate your strategies, this guide has you covered.

📌 Key Takeaways – Binance API

  • REST API: HTTP-based requests for account data, market info, and order management
  • WebSocket API: Real-time, persistent connections for streaming market data
  • API Keys: Ed25519 recommended for best security and performance
  • Rate limits: 1200 request weight/minute (REST), 5 messages/second (WebSocket)
  • Security: Never enable Withdrawals permission, use IP whitelisting, rotate keys every 90 days
  • SDKs: Official Python, Node.js, and Java SDKs available

🔌 What Is Binance API?

The Binance API is a set of programming interfaces that allow developers to interact programmatically with Binance's trading infrastructure. It enables you to access market data, manage orders, track account balances, and build automated trading systems — all without using the Binance web interface.

What you can build with Binance API:

  • Trading bots: Automated strategies that execute trades based on market conditions
  • Market data dashboards: Real-time price and volume tracking
  • Arbitrage systems: Exploit price differences across exchanges
  • Portfolio trackers: Monitor account balances and performance
  • Alert systems: Get notifications for price movements and trade executions
  • Risk management tools: Automated position monitoring and stop-losses

API base endpoints (2026):

  • Spot: https://api.binance.com
  • Futures (USDⓈ-M): https://fapi.binance.com
  • Testnet: https://testnet.binancefuture.com for WebSocket

💡 API Evolution in 2026

Binance has significantly expanded its API capabilities in 2026. Recent updates include SBE (Simple Binary Encoding) market data streams, WebSocket base URL migration, and new endpoints for Block Trades. The API now supports Ed25519 keys for enhanced security.

⚡ REST API vs WebSocket API

Binance offers two primary API types, each designed for different use cases:

Feature REST API WebSocket API
Connection Type HTTP request-response Persistent two-way connection
Real-Time Data ❌ Polling required ✅ Instant streaming
Best For Order placement, account data, historical data Live market data, ticker updates, order book depth
Rate Limits 1200 request weight/minute 5 messages/second, 24-hour connection
Latency Higher (HTTP overhead) Lower (persistent connection)

When to use each:

  • Use REST API for placing orders, fetching account balances, checking order status, and getting historical kline/candlestick data.
  • Use WebSocket API for real-time price updates, order book depth, trade execution streams, and user data streams (account updates).

The WebSocket base endpoint is wss://ws-dapi.binance.com/ws-dapi/v1. WebSocket connections are valid for up to 24 hours — you must send PING messages every 30 seconds to keep the connection alive.

🔑 Getting Started – Creating API Keys

Step 1

Log In to Your Binance Account

Log in to your Binance account via the website or mobile app.

Step 2

Navigate to API Management

Go to Account → API Management (or Profile → API Management).

Step 3

Create a New API Key

Click Create API Key. Give it a clear label (e.g., "TradingBot-VPS"). You'll be prompted to complete 2FA verification (Google Authenticator is recommended).

Step 4

Select API Key Type

Binance recommends using Ed25519 API keys for the best performance and security. Ed25519 provides security comparable to 3072-bit RSA keys with smaller key sizes and faster signature computation.

Step 5

Set Permissions – Least Privilege

Only enable the permissions your application actually needs:

  • Enable Reading: ✅ Required for all API calls
  • Enable Spot & Margin Trading: ✅ Only if your bot places trades
  • Enable Withdrawals:NEVER enable this — a compromised key could drain your account
  • Enable Symbol Whitelist: ✅ Optional — restrict trading to specific symbols
Step 6

Save Your Secret Key

After creating the key, Binance will display your API Key and Secret Key. Store your Secret Key securely — you won't see it again. Never share it with anyone.

Step 7

Set IP Restrictions (Recommended)

Add your server's IP address to the whitelist. This ensures only your server can use the API key.

Critical: Never enable Withdrawals permission for API keys used in trading bots. A compromised key with withdrawal permissions could result in complete loss of funds. Always follow the principle of least privilege.

🔒 Authentication – How to Sign Requests

All Binance API requests that require authentication must be signed. Here's how it works:

Signature generation steps:

  1. Sort your request parameters alphabetically
  2. Create a query string (e.g., symbol=BTCUSDT&side=BUY&type=LIMIT)
  3. Append the timestamp parameter: timestamp=1734567890123
  4. Create the preHash string: symbol=BTCUSDT&side=BUY&type=LIMIT&timestamp=1734567890123
  5. Sign with HMAC-SHA256 using your Secret Key
  6. Add the signature to your request

Example (Python):

import hmac import hashlib import time secret_key = b'your_secret_key' params = { 'symbol': 'BTCUSDT', 'side': 'BUY', 'type': 'LIMIT', 'quantity': '0.001', 'price': '60000', 'timestamp': int(time.time() * 1000) } query_string = '&'.join([f"{k}={v}" for k, v in sorted(params.items())]) signature = hmac.new(secret_key, query_string.encode('utf-8'), hashlib.sha256).hexdigest() params['signature'] = signature

API Key Headers:

  • X-MBX-APIKEY: Your API key (required for all authenticated requests)
  • X-MBX-TIMESTAMP: The timestamp (milliseconds since epoch)
  • X-MBX-SIGNATURE: The HMAC-SHA256 signature

📊 Rate Limits – Understanding Request Weights

Binance enforces rate limits to ensure fair usage of its API infrastructure.

Limit Type Limit Value Applies To
REST API Weight 1200 weight per minute All REST endpoints (each endpoint has a specific weight)
Order Rate 10 orders per second New order requests
Order Rate (24h) 100,000 orders per 24 hours All orders combined
WebSocket Messages 5 messages per second WebSocket API connections
WebSocket Connection 24 hours max Each WebSocket connection

Rate limit headers:

  • X-MBX-USED-WEIGHT-1M: Weight used in the last 1 minute
  • X-MBX-ORDER-COUNT-1S: Orders placed in the last 1 second
  • X-MBX-ORDER-COUNT-1M: Orders placed in the last 1 minute
  • X-MBX-ORDER-COUNT-10S: Orders placed in the last 10 seconds

💡 Rate Limit Best Practices

  • Monitor headers: Check response headers to track your usage
  • Implement retry logic: Handle HTTP 429 (rate limit exceeded) with exponential backoff
  • Cache data: Cache market data instead of polling frequently
  • Use WebSocket for real-time: Reduce REST API calls by using WebSocket streams

📡 Key REST API Endpoints

Here are the most commonly used Binance REST API endpoints:

Public Endpoints (No Authentication)

  • GET /api/v3/ping: Test connectivity
  • GET /api/v3/time: Check server time
  • GET /api/v3/exchangeInfo: Get exchange trading rules and symbol information
  • GET /api/v3/klines: Get candlestick/kline data (max 1000 bars per request)
  • GET /api/v3/ticker/price: Get current price for a symbol
  • GET /api/v3/ticker/bookTicker: Get best bid/ask price

Private Endpoints (Require Authentication)

  • GET /api/v3/account: Get account information (balances)
  • POST /api/v3/order: Place a new order
  • GET /api/v3/order: Check order status
  • DELETE /api/v3/order: Cancel an order
  • GET /api/v3/allOrders: Get all orders (active and historical)
  • GET /api/v3/myTrades: Get account trade history

🔌 WebSocket API – Real-Time Data Streaming

The Binance WebSocket API provides real-time, low-latency access to market data and user account updates.

WebSocket base endpoints (2026):

  • Public market data: wss://fstream.binance.com/public
  • Regular market data: wss://fstream.binance.com/market
  • WebSocket API: wss://ws-dapi.binance.com/ws-dapi/v1

Key WebSocket streams:

  • Trade streams: Real-time trade execution data
  • Depth streams: Order book updates (level 1, level 2)
  • Kline streams: Candlestick updates
  • Ticker streams: 24-hour rolling window price statistics
  • User data streams: Account updates (balance changes, order status) — requires Listen Key authentication

WebSocket connection management:

  • Ping/Pong: Send PING messages every 30 seconds to keep connection alive
  • Reconnection: Implement automatic reconnection logic for dropped connections
  • Authentication: API Key must be included in the WebSocket request header as X-MBX-APIKEY

Listen Token for User Data Streams:

  • Request a listen token via REST API (POST /api/v3/userDataStream)
  • Connect to WebSocket using the listen token
  • Renew the listen token periodically (every 30-60 minutes)

🤖 Building a Simple Trading Bot

Here's a high-level overview of building a trading bot with Binance API:

1. Architecture Overview

  • Data layer: WebSocket streams for real-time market data or REST API for historical data
  • Strategy layer: Your trading logic (e.g., moving average crossover, RSI, arbitrage)
  • Execution layer: REST API for placing orders
  • Monitoring layer: Track positions, P&L, and bot health

2. Basic Bot Workflow

  1. Initialize: Connect to Binance API, authenticate, and load configuration
  2. Fetch data: Get market data via WebSocket streams
  3. Analyze: Apply your trading strategy to the data
  4. Decision: Determine if a trade signal is generated (buy, sell, or hold)
  5. Execute: Place orders via REST API (limit or market orders)
  6. Monitor: Track open positions and adjust as needed
  7. Log: Record all trades and bot activity for analysis

Environment variables (production):

BINANCE_API_KEY=your_api_key_here BINANCE_API_SECRET=your_secret_key_here BINANCE_BASE_URL=https://api.binance.com

3. Using Binance's Official SDKs

Binance provides official SDKs for multiple programming languages:

  • Python: binance-sdk-spot (requires Python 3.10+)
  • Node.js: Official Node.js SDK
  • Java: Official Java SDK

Python example – placing an order:

from binance_sdk_spot.spot import Spot, ConfigurationRestAPI config = ConfigurationRestAPI(api_key="your_api_key", api_secret="your_secret") client = Spot(config) # Place a limit order order = client.new_order( symbol="BTCUSDT", side="BUY", type="LIMIT", quantity="0.001", price="60000" ) print(order)

🛡️ Security Best Practices

Follow these security practices to protect your Binance API keys and funds:

1. Use Ed25519 Keys

Binance recommends using Ed25519 API keys as they provide the best security and performance. They offer security comparable to 3072-bit RSA keys with smaller key sizes.

2. Never Enable Withdrawals

Never enable Withdrawals permission for API keys used in trading bots. A compromised key with withdrawal permissions could drain your entire account. Only enable the permissions your application actually requires.

3. Use IP Whitelisting

Add your server's IP address to the API key's whitelist. This ensures only your server can use the key.

4. Rotate Keys Regularly

Delete and recreate API keys every 90 days to ensure you're regularly evaluating the third-party platforms you connect to. If an API key is ever exposed, revoke it immediately.

5. Store Secrets Securely

Never hardcode API keys in your source code. Use environment variables, secrets managers, or encrypted vaults.

6. Enable 2FA

Always use two-factor authentication (2FA) for your Binance account. Google Authenticator is recommended over SMS.

7. Monitor API Key Usage

Regularly review your API keys and delete keys that are no longer in use.

Critical: API keys expire after 90 days of inactivity. Log in occasionally or the key will deactivate. Always test your bot on the testnet before going live with real funds.

📚 SDKs and Libraries

Here are the most popular Binance API libraries and SDKs:

Official Binance SDKs

  • Python: binance-sdk-spot — Official Spot REST API and WebSocket SDK
  • Python (Derivatives): binance-sdk-derivatives-trading-coin-futures
  • Node.js: Official Node.js SDK
  • Java: Official Java SDK

Community Libraries

  • python-binance: Popular community Python library
  • unicorn-binance-websocket-api: Python WebSocket API SDK
  • Binance API documentation: Official GitHub repository

Testing Environments

  • Demo/Testnet: https://demo.binance.com — Practice with virtual funds
  • Testnet WebSocket: wss://testnet.binancefuture.com/ws-dapi/v1

❓ Frequently Asked Questions

What is Binance API and what can I build with it?
Binance API is a set of programming interfaces that allow developers to interact programmatically with Binance's trading infrastructure. You can build trading bots, automated portfolio trackers, market data dashboards, arbitrage systems, and custom trading applications. The API supports REST endpoints for HTTP requests and WebSocket streams for real-time market data.
How do I create a Binance API key?
To create a Binance API key: 1) Log in to your Binance account. 2) Go to Account → API Management. 3) Click 'Create API Key'. 4) Give it a label (e.g., 'MyTradingBot'). 5) Select the required permissions (Reading, Trading, etc. — NEVER enable Withdrawals for trading bots). 6) Complete 2FA verification. 7) Store your Secret Key securely — you won't see it again.
What are the Binance API rate limits in 2026?
Binance REST API has a rate limit of 1200 request weight per minute, with a weight-based system where each endpoint consumes a specific weight. The order rate limit is 10 orders per second and 100,000 orders per 24 hours. WebSocket connections accept a maximum of 5 messages per second and expire after 24 hours. Rate limits are shared between REST and WebSocket API.
What is the difference between REST API and WebSocket API on Binance?
REST API is used for HTTP requests — placing orders, fetching account data, and checking market info. It's request-response based and suitable for non-time-critical operations. WebSocket API provides real-time, persistent connections for streaming market data (ticker updates, order book depth, trade execution). WebSocket is essential for high-frequency trading and real-time applications where low latency matters.
Is Binance API free to use?
Yes, Binance API is free to use. There are no additional charges for API access beyond standard trading fees (0.10% spot trading fee). However, rate limits apply — 1200 request weight per minute for REST API and 5 messages per second for WebSocket API. Exceeding these limits will result in rate limit errors (HTTP 429).

📢 Educational Disclaimer

This content is for educational and informational purposes only. It does not constitute financial advice. Cryptocurrency trading involves substantial risk of loss. Past performance does not guarantee future results. Always do your own research and consult a financial advisor before making investment decisions.

FinorixPro Editorial Team

About the Author

FinorixPro Editorial Team – Crypto trading educators with 5+ years of experience in the financial markets. Our team combines expertise in technical analysis, blockchain technology, and risk management to provide actionable insights for US investors.