Mastering Binance API Keys: Three Permission Tiers, IP Whitelisting, and Emergency Leak Response
Binance API keys ship with three permission tiers (read-only, trading, withdrawal). Withdrawals are off by default, IP whitelists cap at 4 IPv4 addresses. This guide covers key creation, HMAC-SHA256 signing fundamentals, quant-bot isolation, and the 30-second emergency drill for leaked keys.
The security model of the Binance API sits on three switches: Read Info (read only), Enable Spot & Margin Trading, and Enable Withdrawals (off by default). Each key can pin up to four IPv4 addresses in its whitelist, and every request is signed with HMAC-SHA256. Once a key leaks, you have to complete three moves within roughly thirty seconds (delete the key, close open positions, rotate the password) to have any chance of preserving remaining assets.
1. What Each Permission Tier Actually Allows
Understanding the tier system is the first step to using the API safely. Many retail users tick every checkbox to save trouble, then lose everything on the first leak.
1.1 Read-Only (Read Info)
Read Info lets you fetch balances, order history, klines, and position details. It cannot place orders and cannot move funds. Ideal for tax reporting tools, market dashboards, and data backup scripts. Highest safety tier: even if the key leaks, the worst outcome is a privacy leak.
1.2 Spot / Futures Trading
Trading permission allows placing orders, cancelling orders, opening and closing futures positions, but still cannot withdraw. This is the most common tier for quant bots. If an attacker gets this key, the worst-case outcome is dumping your spot inventory or opening high-leverage liquidation traps. That is why an IP whitelist is mandatory here.
1.3 Enable Withdrawals
Withdrawal permission means API calls can move funds to a whitelisted destination address. Most workflows never need this, so the Binance Official Site keeps the switch off and greyed out by default. You must bind an IP whitelist and pass a second 2FA challenge to enable it.
1.4 Recommended Combinations
| Use case | Read | Trade | Withdraw | Notes |
|---|---|---|---|---|
| Tax / dashboard | Yes | No | No | Safest |
| Quant bot | Yes | Yes | No | Standard |
| Market-making automation | Yes | Yes | No | IP whitelist mandatory |
| Scheduled cold-wallet sweep | Yes | No | Yes | Rare, high risk |
| One-off arbitrage | Yes | Yes | No | Delete after use |
2. IP Whitelist Rules
The IP whitelist is the second lock in Binance's API security model. Arguably it matters more than 2FA does.
2.1 Quantity and Format Limits
- Up to 4 IPv4 addresses per key
- IPv6 is not yet supported; IPv6-only servers need an IPv4 tunnel
- CIDR ranges (e.g. 1.2.3.0/24) are not accepted
- A key without any IP whitelist has a 90-day lifetime and expires automatically
2.2 Common Cloud Pitfalls
On AWS, Google Cloud, and Azure, the whitelist should hold the instance's Elastic IP or reserved static IP. Binding an ephemeral IP on an autoscaling group means the IP changes on restart, immediately breaking API calls with 403. Practical patterns:
- Reserve and pin an Elastic IP
- Fix a NAT Gateway IP inside the VPC
- Egress through a reverse proxy with a stable IP
- Add CloudWatch monitoring on IP changes to trigger SNS alerts
2.3 How the Whitelist Cooperates with Request Signing
Even if the IP matches, the request must also be HMAC-SHA256 signed with the correct API Secret. It is an AND relationship. This double lock means simply spoofing an IP is not enough to defeat Binance's validation.
3. HMAC-SHA256 Signing Fundamentals
For developers touching the Binance API for the first time, signing is the biggest hurdle. Understand the flow once and debugging becomes routine.
3.1 Concatenating Signature Inputs
The raw signing string is all query parameters concatenated in order, for example:
symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000×tamp=1699999999999
The timestamp must be Unix milliseconds; the offset from Binance's server clock must be within recvWindow (default 5000 ms, max 60000 ms).
3.2 Computing the Signature and Request Header
- Algorithm: HMAC-SHA256(key = API Secret, message = raw string above)
- Append the hex digest as a query parameter:
...&signature=xxx - HTTP header:
X-MBX-APIKEY: <API Key>
3.3 Common Error Codes
| Code | Meaning | Fix |
|---|---|---|
| -1021 | Timestamp drift too large | Sync NTP, check timezone |
| -1022 | Invalid signature | Check parameter order and URL encoding |
| -2015 | Invalid key, IP not whitelisted, or insufficient permission | Check all three |
| -1003 | Too many requests | Slow down or use WebSocket |
| -4028 | Key expiring soon | Rotate seven days early |
Q: I am placing a spot order, all parameters look right, but I keep getting -1022. Why?
A: 99% of the time the query string contains a URL-encoded plus sign + (should be %2B) or an unencoded space. Print the exact URL sent to Binance alongside the local pre-sign string and compare character by character.
4. Isolation Strategy for Quant Bots
Large quant teams typically manage dozens of keys. Isolation is the operational baseline.
4.1 One Strategy, One Key
Every strategy (market maker, copy trader, grid bot, futures-spot arb) gets its own key. Multiple servers running the same strategy can share the key by putting all four server IPs on the whitelist. When one strategy has a problem, only that key is affected.
4.2 Minimum Permission
Even if a strategy needs both spot and futures, do not grant a single unified "all permissions" key. Split into two keys: one spot-only, one futures-only, and switch between them in code.
4.3 Regular Rotation
High-frequency strategies should rotate keys every 30 days, mid- and low-frequency every 90 days. Set up expiry notifications inside the Official Binance App so you do not forget. Additional operational tools are documented on the Security and Download pages.
4.4 Environment Variables and Secret Management
- Never hard-code keys in source or Git history
- Prefer Hashicorp Vault, AWS Secrets Manager, or KMS-encrypted files
- Local dev with
.envmust include the file in.gitignore - CI/CD injects secrets as protected variables; build logs are masked
5. The 30-Second Leak Response Playbook
Once you suspect a leak, the faster you move, the less you lose. Below is the "golden 30 seconds" drill.
5.1 Delete the Key Immediately
Sign in to Binance Official Site, go to API Management, find the suspicious key, click Delete. Deletion is the strongest instant action; the attacker cannot place further orders.
5.2 Close Positions and Cancel Orders
After deletion, check futures positions for any freshly opened high-leverage exposures. If present, close them manually on the web console and cancel all open orders to prevent chained liquidations.
5.3 Rotate Password and 2FA
Reset the account password through the standard flow. If you cannot be sure the 2FA is intact, rebind Google Authenticator. See our companion guide on Binance 2FA device migration.
5.4 Audit and Open a Ticket
Under Security Centre, open the Account Activity log, export the last 30 days of API call records as evidence, and file a ticket with Binance's security team requesting risk control freeze and asset traceback.
Risk note: anyone claiming to be a "Binance engineer" who will recover your loss for a service fee is 100% a scammer. Real Binance never DMs users first and never asks for payment.
6. Frequently Asked Questions
I have not used a key for three months. Is it still valid?
Depends on the whitelist. Keys with an IP whitelist have no expiry and remain valid as long as the account exists. Keys without a whitelist expire every 90 days and need to be recreated.
My bot returns -2015. How do I diagnose?
Check in order: has the key been deleted; is your egress IP inside the four IPv4 slots on the whitelist; is the operation within the key's granted permissions (e.g. using a read-only key to place orders). Only after those three are ruled out should you investigate the signature.
Is HMAC-SHA256 mandatory? Can I use Ed25519?
Binance has been rolling out Ed25519 and RSA signing since 2024 as high-performance alternatives. They are not recommended for beginners because they add a keypair generation step. Mainstream SDKs still default to HMAC-SHA256.
Is there a cap on the number of API keys?
A regular account can create up to 30 keys. To create more, delete an old one first. Institutional VIPs can apply to lift the cap to 60.
Do unused keys get auto-cleaned?
Keys without IPs expire every 90 days. Keys with IPs are never cleaned unless the account itself is disabled. To reduce blast radius, manually audit the key list every quarter and remove anything unused.
Published 2026-07-01, next re-test scheduled 2026-10-01.