GEX
Public feedInitializing terminal
Error codes and handling
All API errors return a JSON response with an HTTP status code and a detail field describing the error. The response body always has the following format:
{
"detail": "Human-readable error description"
}| Name | Type | Required | Description |
|---|---|---|---|
| 400 | Bad Request | Optional | Invalid request parameters. Check path parameters, query parameters, or request body format. |
| 401 | Unauthorized | Optional | Missing or invalid API key. Ensure the X-API-Key header is present and contains a valid key. |
| 403 | Forbidden | Optional | Your API key does not have permission to access this resource. Check your plan tier. |
| 404 | Not Found | Optional | The requested resource does not exist. Check the endpoint path and symbol parameter. |
| 429 | Too Many Requests | Optional | Rate limit exceeded. Check the X-RateLimit-* response headers for limit details and retry timing. |
| 500 | Internal Error | Optional | An unexpected error occurred on the server. Retry the request. If it persists, contact support. |
| 503 | Service Unavailable | Optional | The service is temporarily unavailable, typically during deployments or maintenance windows. |
When you receive a 429 response, the following headers are included to help you implement backoff:
WebSocket connections may be closed with these application-specific codes:
| Name | Type | Required | Description |
|---|---|---|---|
| 4003 | Authentication | Optional | Authentication failed. The api_key query parameter is missing, invalid, or expired. |
| 4008 | Capacity | Optional | Connection limit reached. You have exceeded the maximum number of concurrent WebSocket connections for your plan. |
Best practices for error handling:
For 429 errors, implement exponential backoff using the X-RateLimit-Reset header. Do not retry immediately -- wait until the reset timestamp.
For 500 and 503 errors, retry with exponential backoff (1s, 2s, 4s) up to 3 attempts. If the error persists, the service may be experiencing an incident.
For 400 errors, do not retry -- fix the request parameters. The detail field will describe exactly what is wrong.
import requests
import time
def fetch_with_retry(url, headers, max_retries=3):
for attempt in range(max_retries):
resp = requests.get(url, headers=headers)
if resp.status_code == 200:
return resp.json()
if resp.status_code == 429:
reset = int(resp.headers.get("X-RateLimit-Reset", 0))
wait = max(reset - time.time(), 1)
print(f"Rate limited. Waiting {wait:.0f}s...")
time.sleep(wait)
continue
if resp.status_code in (500, 503):
wait = 2 ** attempt
print(f"Server error {resp.status_code}. Retry in {wait}s...")
time.sleep(wait)
continue
# Client error -- do not retry
resp.raise_for_status()
raise Exception("Max retries exceeded")
data = fetch_with_retry(
"https://api.gexengine.com/v1/gex/SPX",
{"X-API-Key": "YOUR_API_KEY"}
)