APIError Class
All HTTP errors from the SDK are thrown asAPIError instances. Inspect the status, message, and data properties to determine what went wrong.
APIError Properties
Common Status Codes
withRetry Wrapper
The SDK provides awithRetry utility function that wraps any async operation with configurable retry logic.
withRetry Options
Only
APIError instances with a matching status code trigger retries. Other errors (network failures, timeouts) are thrown immediately.@retryOnErrors Decorator
For class-based architectures, use the@retryOnErrors decorator to add retry logic to individual methods.
Decorator Options
@retryOnErrors takes the same RetryConfigOptions as withRetry.
When
delays is omitted, the delay for each retry is calculated (in seconds) as:
exponentialBase: 2 and maxDelay: 60:
Rate Limiting with OrderQueue
For high-frequency trading scenarios, implement anOrderQueue to throttle outgoing requests and avoid 429 errors:
Best Practices
Always handle APIError specifically
Always handle APIError specifically
Catch
APIError separately from other errors. Network failures, JSON parse errors, and timeouts are not APIError instances and should be handled differently.Do not retry 400 or 401 errors
Do not retry 400 or 401 errors
Client errors (400, 401, 403) indicate a problem with your request or credentials. Retrying them wastes time and API quota. Only retry transient server errors (429, 5xx).
Use exponential backoff for 429 responses
Use exponential backoff for 429 responses
When rate limited, the server may include a
Retry-After header. If available, respect it. Otherwise, use exponential backoff starting at 1 second.Combine retry with OrderQueue
Combine retry with OrderQueue
For the most robust setup, use
OrderQueue to throttle request rate and withRetry or @retryOnErrors to handle transient failures:Logging
The SDK provides optional logging through a simpleILogger interface. Logging is completely opt-in with zero overhead by default.
Quick Start
Log Levels
Custom Logger for Production
Implement theILogger interface to integrate with your own logging infrastructure:
Passing Logger to SDK Components
All SDK components accept an optional logger:The SDK automatically redacts API keys in logs (shown as
***). Private keys are never logged.