Skip to main content

APIError Class

All HTTP errors from the SDK are thrown as APIError instances. Inspect the status, message, and data properties to determine what went wrong.

APIError Properties

Common Status Codes

withRetry Wrapper

The SDK provides a withRetry 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:
For example, with exponentialBase: 2 and maxDelay: 60:

Rate Limiting with OrderQueue

For high-frequency trading scenarios, implement an OrderQueue to throttle outgoing requests and avoid 429 errors:

Best Practices

Catch APIError separately from other errors. Network failures, JSON parse errors, and timeouts are not APIError instances and should be handled differently.
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).
When rate limited, the server may include a Retry-After header. If available, respect it. Otherwise, use exponential backoff starting at 1 second.
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 simple ILogger interface. Logging is completely opt-in with zero overhead by default.

Quick Start

Log Levels

Custom Logger for Production

Implement the ILogger 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.