How to Connect an AI Trading Agent to Binance API
Prerequisites
- Verified Binance account (full KYC required)
- Python 3.8+
Step 1: Create Account
Create Binance account → Full KYC required — cannot be automated.
Step 2: Generate API Keys
- Account → API Management → Create API
- Label it (e.g. "trading-agent")
- Enable: Read Info, Spot Trading, Futures
- Restrict to your server IP
- Save Key and Secret — shown once only
Step 3: Connect with CCXT
pip install ccxt
import ccxt, os
exchange = ccxt.binance({
"apiKey": os.environ["BINANCE_API_KEY"],
"secret": os.environ["BINANCE_SECRET"],
})
balance = exchange.fetch_balance()
print(balance["USDT"]["free"])
order = exchange.create_market_buy_order("BTC/USDT", 0.001)
print(order)
Step 4: Use Testnet First
exchange.set_sandbox_mode(True)
# Keys from: testnet.binance.vision
Or Use Skills Hub (No-code)
npx skills add https://github.com/binance/binance-skills-hub --full-depth
Note: Skills Hub covers spot only. For futures, use the REST API directly.
Key Tips
- Rate limit: 1200 req/min — respect it or get IP banned
- Use WebSocket for real-time price data, not polling
- Never hardcode API keys — use environment variables