API Errors Comuns: O Que Significam e Como Resolver

API errors comuns: HTTP codes, exchange-specific, soluções.

API errors são inevitable em qualquer setup com APIs externas. Esta página cobre os mais comuns.

HTTP status codes

  • 400 Bad Request: sua request está mal-formatted. Check params.
  • 401 Unauthorized: auth falhou. API key, signature.
  • 403 Forbidden: auth OK mas permissions insuficientes (ou IP whitelist).
  • 404 Not Found: endpoint errado ou recurso não existe.
  • 429 Too Many Requests: rate limit. Backoff.
  • 500 Internal Server Error: exchange teve problema. Retry.
  • 502/503/504: gateway issues. Retry com exponential backoff.

Binance-specific

  • -1021 Timestamp: sync NTP, time drift > 1s
  • -1022 Invalid signature: regenere signature
  • -2010 NEW_ORDER_REJECTED: ordem viola filters (lot size, price, etc.)
  • -2014 BAD_API_KEY_FMT: API key malformed

Bybit-specific

  • 10001 Param error: verifique parameter format
  • 10002 Time too old/new: time sync issue
  • 110007 Insufficient balance
  • 110009 Limit price not met

Retry strategy

Bot bem-feito implementa:

def retry_with_backoff(func, max_retries=3):
    for i in range(max_retries):
        try:
            return func()
        except RetryableError as e:
            wait = 2 ** i  # exponential
            sleep(wait)
    raise  # propagate after max retries

Errors que NÃO retry

  • 4xx errors (your fault) — não retry, fix the bug
  • Insufficient balance — retry não conserta
  • Invalid order params — retry envia mesmo bug

Errors que retry

  • 429 Rate limit (com backoff)
  • 500/502/503/504 (exchange issue)
  • Network timeouts
  • Temporary maintenance

Logging

Log every API call com: timestamp, endpoint, params, response code, response body (truncated). Crucial pra debug.

Veja: troubleshooting geral. 🦞