Overview
The SDK provides structured error types, a retry decorator for transient failures, and configurable logging to help you build resilient trading applications.APIError
All non-2xx HTTP responses from the API raise anAPIError exception:
| Property | Type | Description |
|---|---|---|
status_code | int | HTTP status code (e.g. 400, 401, 429, 500) |
message | str | Raw JSON response body from the API |
Common Status Codes
| Code | Meaning | Typical Cause |
|---|---|---|
400 | Bad Request | Invalid order parameters, malformed payload |
401 | Unauthorized | Missing or invalid API key |
403 | Forbidden | Insufficient permissions or geographic restriction |
404 | Not Found | Invalid market slug or order ID |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Transient server-side failure |
Retry Decorator
Use the@retry_on_errors decorator to automatically retry operations that fail with specific status codes:
| Parameter | Type | Description |
|---|---|---|
status_codes | set[int] | HTTP status codes that trigger a retry |
max_retries | int | Maximum number of retry attempts |
delays | list[float] | Delay in seconds before each retry (supports exponential backoff) |
on_retry | callable | None | Optional callback invoked on each retry with (attempt, error) |
The decorator only retries on
APIError exceptions whose status_code is in the status_codes set. All other exceptions propagate immediately.RetryableClient
For broader retry coverage, wrap yourHttpClient with the RetryableClient. This applies retry logic to all API calls made through the client:
Debugging with ConsoleLogger
Enable verbose logging to trace requests, responses, and internal operations:DEBUG level, the logger outputs:
- Request and response headers
- Venue cache hits and misses
- Full API response bodies
- Retry attempts and delays
- WebSocket connection state changes
Example DEBUG output
Example DEBUG output
Best Practices
Always handle APIError
Wrap every API call in a try/except block. Log the
status_code and message for diagnostics:Retry only transient errors
Limit retries to status codes like
429 (rate limit) and 5xx (server errors). Do not retry 400 (bad request) or 401 (auth failure) as these require corrective action:Close the client on exit
Always close the
HttpClient to release connections, even if an error occurs:Known Issues and Workarounds
NoOpLogger .warning() bug
NoOpLogger .warning() bug
The SDK’s
NoOpLogger calls .warning() but the logger interface only defines .warn(). Add this patch at the top of your script:get_orderbook() Pydantic validation error
get_orderbook() Pydantic validation error
MarketFetcher.get_orderbook() may throw a Pydantic ValidationError when lastTradePrice is null. Use curl as a workaround:urllib.request returns 403
urllib.request returns 403
Python’s built-in
urllib.request gets blocked by the API (403 Forbidden). Use the SDK’s HttpClient, the requests library, or curl via subprocess instead.