📖 Guias Operacionais

API do Gate.io: Tutorial para Desenvolvedores e Traders Brasileiros

Tutorial da Gate.io API — como criar keys, usar REST/Websocket API e build bots para automated trading com BRL focus.

2026-07-12 · Demonjoy — Brasil

API do Gate.io: Tutorial para Desenvolvedores e Traders Brasileiros

Gate.io API permite automated trading, data collection e portfolio management via code. Para brasileiros com programming skills, API é powerful tool para building bots, tracking prices em BRL e executing strategies automatically.

O Que É API?

API (Application Programming Interface) é a bridge between your code and Gate.io’s systems:

  • REST API — HTTP requests for trading, account info, market data
  • WebSocket API — Real-time streaming data (prices, order book, trades)
  • Authentication — API keys required for trading operations

Creating API Keys

Step 1: Access API Management

  1. Login no Gate.io
  2. Settings → API Management → “Create API Key”

Step 2: Configure Key

  • Label — Name your key (ex: “Trading Bot”, “Portfolio Tracker”)
  • Password — Set strong password for the key
  • Permissions:
    • Read only — View balance, orders, market data (SAFE — use for trackers)
    • Read + Trading — Can place/cancel orders (MODERATE RISK)
    • Read + Trading + Withdrawals — Can withdraw funds (HIGH RISK — avoid!)

Recommendation: Use read-only keys for portfolio trackers. Use read+trading only for actual bots. NEVER enable withdrawal via API.

Step 3: Security

  • 2FA required — Enter Google Authenticator code
  • IP whitelist — Add your server IPs (recommended)
  • Key generated — Save API key and secret immediately
  • Secret shown once — If you lose it, must regenerate key

CRITICAL: Store API secret securely — password manager or environment variable. Never commit to code repository.

REST API Basics

Base URLs

  • Spot: https://api.gateio.ws/api/v4
  • Futures: https://api.gateio.ws/api/v4/futures

Authentication

Every authenticated request needs:

  1. API key — In header KEY
  2. Timestamp — Current Unix timestamp
  3. Signature — HMAC-SHA512 of (request method + URL + body + timestamp)
  4. Secret — Used to generate signature

Example: Get Spot Balances

import requests
import time
import hashlib
import hmac

api_key = "your_api_key"
api_secret = "your_api_secret"

url = "https://api.gateio.ws/api/v4/spot/accounts"
timestamp = str(int(time.time()))

# Generate signature
signature = hmac.new(
    api_secret.encode(),
    f"GET\n/accounts\n\n{timestamp}".encode(),
    hashlib.sha512
).hexdigest()

headers = {
    "KEY": api_key,
    "SIGN": signature,
    "Timestamp": timestamp
}

response = requests.get(url, headers=headers)
balances = response.json()

# Find USDT balance
for account in balances:
    if account['currency'] == 'USDT':
        print(f"USDT balance: {account['available']}")

Example: Place Spot Order

url = "https://api.gateio.ws/api/v4/spot/orders"

order_data = {
    "currency_pair": "BTC_USDT",
    "type": "market",
    "side": "buy",
    "amount": "0.001"  # BTC amount
}

# POST request with signature
signature = hmac.new(
    api_secret.encode(),
    f"POST\n/orders\n{json.dumps(order_data)}\n{timestamp}".encode(),
    hashlib.sha512
).hexdigest()

headers = {
    "KEY": api_key,
    "SIGN": signature,
    "Timestamp": timestamp,
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, json=order_data)
order = response.json()
print(f"Order placed: {order['id']}")

WebSocket API

Real-Time Price Streaming

import websocket
import json

def on_message(ws, message):
    data = json.loads(message)
    if 'result' in data:
        price = data['result']['last']
        print(f"BTC/USDT price: {price}")

ws = websocket.WebSocketApp(
    "wss://api.gateio.ws/ws/v4/",
    on_message=on_message
)

# Subscribe to BTC_USDT ticker
subscribe = {"channel": "spot.tickers", "event": "subscribe", "payload": ["BTC_USDT"]}
ws.on_open = lambda ws: ws.send(json.dumps(subscribe))
ws.run_forever()

API Rate Limits

TypeLimit
REST (public)300 requests/min
REST (authenticated)600 requests/min
WebSocket connections10 concurrent
Order placement100 orders/sec

Exceeding limits returns HTTP 429. Implement rate limiting in your code.

Common Use Cases

1. Portfolio Tracker Bot

  • Check balances every minute
  • Calculate total value in BRL (fetch BTC_BRL rate)
  • Alert when portfolio changes >5%

2. DCA Bot

  • Buy fixed USDT amount of BTC every week
  • Automatic limit orders at current price
  • Track all purchases for tax calculation

3. Arbitrage Bot

  • Compare prices across exchanges
  • Buy cheaper, sell more expensive
  • Account for fees and transfer time

4. Grid Trading Bot

  • Place buy orders below current price
  • Place sell orders above current price
  • Profit from range-bound markets

Security Best Practices

  1. Read-only for trackers — Never give trading permission to tracker apps
  2. IP whitelist — Restrict API access to known IPs
  3. Never enable withdrawals — Manual withdrawals only
  4. Rotate keys — Generate new keys every 3-6 months
  5. Monitor usage — Check API logs for suspicious activity
  6. Rate limit — Implement proper rate limiting
  7. Error handling — Handle network errors gracefully
  8. No keys in code — Use environment variables

Dicas para Brasileiros

  1. Start com read-only — Build tracker before trading bot
  2. BRL conversion — Fetch USDT_BRL pair data for local pricing
  3. Test extensively — Use simulated trading API first
  4. Declare automated gains — Track all bot trades for IRPF
  5. Monitor 24/7 — Bots can go wrong; always monitor
  6. Backup API keys — Store securely offline

Para usar API, registre no Gate.io.

Registrar no Gate.io

Gate.io — Brasil

PIX · Taxa mais baixa · Suporte PT

Comece a Negociar com Segurança no Gate.io →