Before you start
- A verified Binance account (identity verification and 2FA enabled)
- For testnet keys instead: a GitHub account
- Optional: the static IP address of the machine that will run the bot
Create your Binance API key
- 1
Open API Management
Log in at binance.com, open the profile menu and choose Account → API Management (
binance.com/en/my/settings/api-management). - 2
Create a system-generated key
Click Create API, choose System generated (HMAC), and give it a label such as
algogp-bot. Complete the email and 2FA confirmation. - 3
Copy the API key and secret
Copy the API Key and Secret Key. The secret is shown only once; if you lose it, delete the key and create a new one.
- 4
Set permissions
Click Edit restrictions. Keep Enable Reading, tick Enable Spot & Margin Trading, and leave Enable Withdrawals and futures off.
- 5
Restrict to trusted IPs
Choose Restrict access to trusted IPs only and add the public IP of the machine that runs the bot. Binance treats unrestricted trading keys as higher risk and may limit them.
- 6
Testnet alternative
For practice, go to
testnet.binance.vision, sign in with GitHub, click Generate HMAC_SHA256 Key, and copy the pair. Testnet keys only work againsthttps://testnet.binance.vision.
Test the key
Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.
TS=$(date +%s000)
QUERY="timestamp=$TS&recvWindow=5000"
SIG=$(printf "%s" "$QUERY" | openssl dgst -sha256 -hmac "$BINANCE_API_SECRET" | sed 's/^.* //')
curl -s -H "X-MBX-APIKEY: $BINANCE_API_KEY" \
"https://testnet.binance.vision/api/v3/account?$QUERY&signature=$SIG"balances means the key and signature work. Use https://api.binance.com for a mainnet key.Add the key to your AlgoGP project
- 1
Open your project’s APIs & keys tab
Open the strategy project, select APIs & keys, and under Platforms choose Binance.
- 2
Paste each value
Paste the values into
BINANCE_API_KEYandBINANCE_API_SECRETand click Save. Values are encrypted at rest, never shown again and never written into code or exports. - 3
Run locally with the same names
Exported projects read the same names from
.env(copy.env.example). Keep.envout of version control.
BINANCE_API_KEY=paste-your-value-here
BINANCE_API_SECRET=paste-your-value-here
# BINANCE_BASE_URL=Security checklist
- No withdrawal permission, ever, on a bot key.
- One key per bot, so revoking one does not stop the others.
- An IP allowlist for any key with trading enabled.
- Store the secret in AlgoGP Keys & secrets or a git-ignored
.env, never in code.
Common Binance API errors
-2015 Invalid API-key, IP, or permissions- Wrong key, a request from an IP not on the allowlist, or trading not enabled on the key.
-1022 Signature for this request is not valid- The signature was computed over a different string than was sent, or the secret is wrong. Sign the exact query string.
-1021 Timestamp outside of recvWindow- The machine clock is off. Sync it with NTP.
-1013 Filter failure: LOT_SIZE / NOTIONAL- Quantity is not a multiple of the step size or the order is below the minimum value.
Frequently asked questions
Can I use a Binance.com key on Binance.US?
No. They are separate exchanges with separate accounts. Create the key on the exchange where your funds are and set BINANCE_BASE_URL for Binance.US.
Do Binance testnet keys expire?
The testnet is reset periodically, which can clear keys and balances. Generate a new pair if yours stops working.
Build a Binance trading bot in minutes
Describe the strategy in plain English, backtest it on years of data, then export Python that already talks to Binance: paper, sandbox and live modes, keys handled for you.
- Generated adapter for Binance orders and balances
- Backtests with costs, slippage and walk-forward checks
- Paper first; live trading only after you opt in
Free plan, no card required.
AlgoGP is not affiliated with Binance. Menus get renamed from time to time; if a label differs, the official documentation has the current path.