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:
Common Status Codes
Retry Decorator
Use the@retry_on_errors decorator to automatically retry operations that fail with specific status codes:
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
1
Always handle APIError
Wrap every API call in a try/except block. Log the
status_code and message for diagnostics:2
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:3
Use exponential backoff
Increase delays between retries to avoid overwhelming the API:
4
Close the client on exit
Always close the
HttpClient to release connections, even if an error occurs:5
Use DEBUG logging during development
Enable
LogLevel.DEBUG to see the full request/response cycle. Switch to INFO or WARN in production to reduce noise.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.