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
📖 Table of Contents
- 1. What Is Binance API?
- 2. REST API vs WebSocket API
- 3. Getting Started – Creating API Keys
- 4. Authentication – How to Sign Requests
- 5. Rate Limits – Understanding Request Weights
- 6. Key REST API Endpoints
- 7. WebSocket API – Real-Time Data Streaming
- 8. Building a Simple Trading Bot
- 9. Security Best Practices
- 10. SDKs and Libraries
- 11. Frequently Asked Questions
🔌 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.comfor 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
Log In to Your Binance Account
Log in to your Binance account via the website or mobile app.
Navigate to API Management
Go to Account → API Management (or Profile → API Management).
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).
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.
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
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.
Set IP Restrictions (Recommended)
Add your server's IP address to the whitelist. This ensures only your server can use the API key.
🔒 Authentication – How to Sign Requests
All Binance API requests that require authentication must be signed. Here's how it works:
Signature generation steps:
- Sort your request parameters alphabetically
- Create a query string (e.g.,
symbol=BTCUSDT&side=BUY&type=LIMIT) - Append the timestamp parameter:
timestamp=1734567890123 - Create the preHash string:
symbol=BTCUSDT&side=BUY&type=LIMIT×tamp=1734567890123 - Sign with HMAC-SHA256 using your Secret Key
- Add the signature to your request
Example (Python):
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
- Initialize: Connect to Binance API, authenticate, and load configuration
- Fetch data: Get market data via WebSocket streams
- Analyze: Apply your trading strategy to the data
- Decision: Determine if a trade signal is generated (buy, sell, or hold)
- Execute: Place orders via REST API (limit or market orders)
- Monitor: Track open positions and adjust as needed
- Log: Record all trades and bot activity for analysis
Environment variables (production):
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:
🛡️ 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.
📚 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
📢 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.