Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.vectrade.io/llms.txt

Use this file to discover all available pages before exploring further.

Error Handling

Error Response Format

All errors follow a consistent JSON structure:
{
  "error": {
    "type": "rate_limit_error",
    "message": "Rate limit exceeded. Please retry after 2 seconds.",
    "docs_url": "https://docs.vectrade.io/guides/error-handling"
  },
  "request_id": "req_abc123def456"
}

Error Types

HTTP StatusError TypeSDK ExceptionRetryable
401authentication_errorAuthenticationErrorNo
403permission_errorAuthenticationErrorNo
404not_foundNotFoundErrorNo
422validation_errorValidationErrorNo
429rate_limit_errorRateLimitErrorYes
429quota_exceededQuotaExceededErrorNo
500server_errorServerErrorYes
502bad_gatewayServerErrorYes
503service_unavailableServerErrorYes

Automatic Retries

The SDK automatically retries failed requests for transient errors (429, 5xx) with exponential backoff:
from vectrade import VecTrade

# Default: 2 retries with exponential backoff
client = VecTrade(max_retries=3)

# Disable retries
client = VecTrade(max_retries=0)

Retry Behavior

  • Initial delay: 0.5 seconds
  • Backoff factor: 2x (0.5s → 1s → 2s → 4s)
  • Jitter: ±25% randomization to prevent thundering herd
  • Retry-After: Server header takes precedence when present
  • Max delay: 30 seconds cap

Exception Hierarchy

VecTradeError
├── ConfigurationError     # Missing API key, invalid config
└── APIError               # All HTTP errors
    ├── AuthenticationError # 401, 403
    ├── NotFoundError      # 404
    ├── ValidationError    # 422
    ├── RateLimitError     # 429 (retryable)
    ├── QuotaExceededError # 429 (not retryable)
    └── ServerError        # 5xx

Handling Errors

from vectrade import VecTrade, RateLimitError, NotFoundError, APIError

client = VecTrade()

try:
    quote = client.quotes.get("INVALID")
except NotFoundError as e:
    print(f"Symbol not found: {e.message}")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
    print(f"Limit: {e.limit}, Remaining: {e.remaining}")
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")
    print(f"Request ID: {e.request_id}")

Request IDs

Every response includes a unique X-Request-Id header. Include this when contacting support:
except APIError as e:
    logger.error(f"API error. Request ID: {e.request_id}")

Rate Limit Headers

Successful responses include rate limit information:
HeaderDescription
X-VQ-RateLimit-LimitMax requests per window
X-VQ-RateLimit-RemainingRequests remaining
X-VQ-RateLimit-ResetWindow reset (Unix timestamp)