API Endpoints and Basics
Binance provides multiple base endpoints for API access, ensuring flexibility and performance optimization:
- Primary Endpoint:
👉 https://api.binance.com Alternate Endpoints (Higher Performance/Less Stability):
https://api1.binance.comhttps://api2.binance.comhttps://api3.binance.comhttps://api4.binance.com
Key Notes:
- All endpoints return JSON objects or arrays.
- Data is sorted in ascending order (oldest first).
- Timestamps are in milliseconds.
HTTP Return Codes and Error Handling
HTTP Status Codes
| Code | Description |
|------|-------------|
| 4XX | Malformed requests (sender-side issue). |
| 403 | WAF (Web Application Firewall) limit violation. |
| 429 | Request rate limit exceeded. |
| 418 | IP banned due to repeated rate limit violations. |
| 5XX | Binance server errors (treat as UNKNOWN status). |
Error Payload Example
{
"code": -1121,
"msg": "Invalid symbol."
}- Refer to Binance Error Codes for specifics.
Endpoint Security and Request Types
Security Types
| Type | Description |
|------|-------------|
| NONE | Publicly accessible. |
| TRADE | Requires API key + HMAC signature. |
| USER_DATA | Requires API key + HMAC signature. |
| MARKET_DATA | Requires API key only. |
Request Methods
- GET: Parameters sent as a query string.
- POST/PUT/DELETE: Parameters in query string or body (
application/x-www-form-urlencoded).
Rate Limits and IP Restrictions
General Limits
- Interval Notation:
S(Second),M(Minute),H(Hour),D(Day). Rate limits are tracked via headers:
X-MBX-USED-WEIGHT-(interval)for IP limits.X-MBX-ORDER-COUNT-(interval)for order limits.
IP-Specific Rules
- 429 Error: Back off immediately to avoid bans.
- 418 Ban: Escalates from 2 minutes to 3 days for repeat offenders.
WebSocket Limits:
- 5 messages/second per connection.
- Max 300 connections/IP every 5 minutes.
Signed Endpoints: HMAC and RSA Examples
HMAC-SHA256 Signature Steps
Concatenate parameters:
symbol=LTCBTC&side=BUY&type=LIMIT×tamp=1499827319559Generate signature:
echo -n "payload" | openssl dgst -sha256 -hmac "API_SECRET"Include in request:
&signature=generated_hash
RSA Key Example (PKCS#8)
Sign payload:
openssl dgst -sha256 -sign private_key.pem- Base64 + URL encode the output.
FAQs
1. How do I avoid IP bans?
- Adhere to rate limits and respect
Retry-Afterheaders.
2. What’s the difference between api and sapi endpoints?
/api/*: Shared IP/UID limits (6000/min)./sapi/*: Independent IP (12000/min) or UID (180000/min) limits.
3. Why is my order rejected with a 429?
- Check
X-MBX-ORDER-COUNT-*headers for current usage.
4. How are WebSocket limits enforced?
- Disconnections occur if exceeding 5 messages/second or 300 connections/IP.
Final Notes
- Data sources prioritize Matching Engine > Memory > Database for freshness.
- Always validate responses and handle errors gracefully.
- Questions? 👉 Contact Support
### Key SEO Adjustments:
- **Keywords**: Binance API, rate limits, HMAC signature, WebSocket, error codes.