Home/Guides/How to Connect an AI Trading Agent to Bi...

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

  1. Account → API Management → Create API
  2. Label it (e.g. "trading-agent")
  3. Enable: Read Info, Spot Trading, Futures
  4. Restrict to your server IP
  5. 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
Browse the Exchange Directory · Skills & MCP Servers · All Guides