Kriptomenjačnica
🟡
Napredni25 min reading

Binance API — Integration & Trading

Binance REST and WebSocket API: HMAC auth, spot and futures orders, live stream.

Binance API Overview

Binance offers one of the most comprehensive trading APIs in crypto. The REST API handles orders and account management; WebSocket streams deliver real-time market data with minimal latency.

Creating API Keys

Binance → Profile → API Management → Create API. Select "System Generated." Enable: "Enable Reading" + "Enable Spot & Margin Trading." Never enable withdrawals on a trading bot key. Whitelist your server IP for extra security.

REST API Endpoints

  • GET /api/v3/ticker/24hr — 24h price stats for all pairs
  • GET /api/v3/klines — OHLCV candlestick data
  • GET /api/v3/account — account balances (signed)
  • POST /api/v3/order — place an order (signed)
  • DELETE /api/v3/order — cancel an order (signed)

Signed Requests

Private endpoints require a signature parameter — HMAC-SHA256 of the query string using your secret key. The timestamp must be within 5000ms of server time. Use python-binance or ccxt to avoid implementing this manually.

WebSocket Streams

Base: wss://stream.binance.com:9443/ws/

  • btcusdt@trade — real-time trades
  • btcusdt@depth20@100ms — order book updates
  • btcusdt@kline_1m — 1-minute candles

Rate Limits

REST: 1200 request weight/minute. WebSocket: 5 connections per IP, up to 1024 subscriptions per connection. Exceeding limits results in temporary IP bans — always implement exponential backoff.