Built into AlgoGPFree
BrokerMarket dataCrypto API key

Binance API guide

Binance runs the deepest crypto order books in the world, and its REST API is the de facto reference design other exchanges copy. Public market data needs no key at all; trading needs a signed request with an API key and secret.

Last verified

Quick answer

Binance’s spot API serves public klines, order books and trades without a key, and signed account and order endpoints with an X-MBX-APIKEY header plus an HMAC-SHA256 signature of the query string. Limits are per-IP request weight reported in response headers (429, then 418 bans); the spot testnet at testnet.binance.vision has separate keys. US residents use Binance.US at api.binance.us.

Binance API at a glance

Pricing
Free API; trading fees apply
Availability
Global ex-US (Binance.US for US residents)
Paper trading
Spot testnet with test funds
Integration type
REST + API key
In AlgoGP
Built in: broker and data adapter (Free)
REST base
https://api.binance.com (Binance.US: https://api.binance.us)
Testnet
https://testnet.binance.vision with separate keys
Auth
X-MBX-APIKEY header + HMAC-SHA256 signature (RSA and Ed25519 also supported)
Candles
GET /api/v3/klines, up to 1,000 bars per request

Public market data: klines without a key

Candlesticks come from GET /api/v3/klines?symbol=BTCUSDT&interval=1d&limit=1000. Each row is [openTime, open, high, low, close, volume, closeTime, …] with prices as strings. Intervals run from 1s and 1m to 1M. History for BTCUSDT goes back to August 2017. Because Binance lists USDT pairs rather than USD, a BTC/USD strategy reads BTCUSDT, and the small USDT/USD basis is worth remembering.

Signed endpoints for trading

Account and order endpoints (GET /api/v3/account, POST /api/v3/order) are SIGNED: you append timestamp (milliseconds) and optionally recvWindow, compute an HMAC-SHA256 of the full query string with your secret, and send it as signature, plus the key in the X-MBX-APIKEY header.

import hashlib, hmac, time, urllib.parse
query = urllib.parse.urlencode({"timestamp": int(time.time() * 1000), "recvWindow": 5000})
signature = hmac.new(SECRET.encode(), query.encode(), hashlib.sha256).hexdigest()
url = f"https://api.binance.com/api/v3/account?{query}&signature={signature}"
The signature AlgoGP’s generated brokers.py computes.
  • Orders must respect each symbol’s filters from GET /api/v3/exchangeInfo: LOT_SIZE (quantity step), PRICE_FILTER and NOTIONAL (minimum order value).
  • A clock that drifts more than recvWindow from Binance’s produces error -1021; keep the machine synced with NTP.

The spot testnet

The spot testnet at testnet.binance.vision mirrors the production API with fake balances. Its keys are created there (sign in with GitHub) and do not work on mainnet, and mainnet keys do not work on the testnet. The testnet order book is thin and is reset from time to time, so use it to prove the plumbing, not to measure fills.

Binance vs Binance.US

US residents cannot use Binance.com and use Binance.US instead, a separate company with its own accounts and keys. Its API follows the same shape at https://api.binance.us, with fewer pairs and some USD-quoted markets. Set BINANCE_BASE_URL to that host and the same code works.

Use Binance in AlgoGP

Open a project, go to the APIs & keys tab and, under Platforms, pick Binance as the market data source (market_data.py) and the broker (brokers.py). The choice is saved to config.json as a new strategy version:

{
  "platforms": {
    "data": "binance",
    "broker": "binance"
  }
}
In-app backtests always use AlgoGP’s normalized history so results stay comparable; this choice decides what backtest.py and live.py connect to when you run the exported code.
KeyWhat it is
BINANCE_API_KEYBinance API key (HMAC). Testnet keys come from testnet.binance.vision.
BINANCE_API_SECRETBinance secret key; shown once when the key is created.
BINANCE_BASE_URL (optional)Optional override, e.g. https://api.binance.us for Binance.US accounts.
Names the generated code reads. Add values under Keys & secrets or in a local .env.
  • TRADING_MODE=paper (default): simulated fills on your machine; the broker is never contacted.
  • TRADING_MODE=sandbox: orders go to Binance’s spot testnet with test funds.
  • TRADING_MODE=live: real orders, and only once LIVE_TRADING_ACKNOWLEDGED=yes is set.

New to Binance? Follow the step-by-step Binance API key guide.

Binance API: frequently asked questions

Do I need an API key to download Binance price history?

No. Klines, tickers and order-book endpoints are public. A key is only needed for account data and trading.

Is there a Binance paper trading API?

Yes: the spot testnet at testnet.binance.vision behaves like production with test funds. It needs its own key pair.

Which Binance API key type should I choose?

System-generated (HMAC) keys are the simplest and are what AlgoGP’s generated code signs. Ed25519 keys are more secure and faster to verify but need a different signing step.

Can my bot withdraw funds?

Only if you enable withdrawals on the key, which you should never do for a trading bot. Enable reading and spot trading only.

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.

Binance alternatives

Independent guide. AlgoGP is not affiliated with Binance. Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.