Overview
The SDK provides a typed error hierarchy, a generic retry function with exponential backoff, aRetryableClient wrapper, and pluggable logging — all following idiomatic Go patterns.
Error Types
All API errors implement theerror interface and can be inspected using errors.As():
APIError
The base error type for all HTTP errors. ItsError() method returns a formatted string like "API error 401 GET /path: message".
| Field | Type | Description |
|---|---|---|
Status | int | HTTP status code (e.g. 400, 401, 429, 500) |
Message | string | Human-readable error message from the API |
Data | json.RawMessage | Raw response body |
URL | string | Request URL path |
Method | string | HTTP method |
Specialized Error Types
The SDK provides three specialized error types that embedAPIError:
| Type | HTTP Status | Description |
|---|---|---|
*ValidationError | 400 | Bad request — invalid parameters or malformed payload |
*AuthenticationError | 401, 403 | Missing/invalid API key or insufficient permissions |
*RateLimitError | 429 | Rate limit exceeded |
OrderValidationError
Client-side validation errors thrown before a request is made:| Field | Type | Description |
|---|---|---|
Field | string | The field that failed validation (e.g. "price", "tokenId") |
Message | string | Description of the validation failure |
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 |
Helper Method
APIError provides an IsAuthError() method to quickly check for authentication issues:
WithRetry (Generic)
The SDK provides a genericWithRetry function that wraps any operation with configurable retry logic using Go generics:
RetryConfig
| Field | Type | Default | Description |
|---|---|---|---|
StatusCodes | []int | [429, 500, 502, 503, 504] | HTTP status codes that trigger a retry |
MaxRetries | int | 3 | Maximum number of retry attempts |
Delays | []time.Duration | nil | Fixed delays per attempt (overrides exponential backoff) |
ExponentialBase | float64 | 2.0 | Base for exponential backoff calculation |
MaxDelay | time.Duration | 60s | Maximum delay between retries |
OnRetry | func(int, error, time.Duration) | nil | Callback invoked on each retry |
WithRetry only retries when the error is an *APIError whose Status is in the StatusCodes list. All other errors propagate immediately.Fixed Delays
Override exponential backoff with explicit per-attempt delays:RetryableClient
For broader retry coverage, wrap yourHttpClient with RetryableClient. This applies retry logic to all API calls made through the client:
RetryableClient has the same methods as HttpClient (Get, GetRaw, Post, Delete) and transparently retries on configured status codes.
Debugging with ConsoleLogger
Enable verbose logging to trace requests, responses, and internal operations:LogLevelDebug, 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
Custom Logger
Implement theLogger interface to plug in your own logging backend:
The
Error method has an additional err error parameter compared to the other methods, allowing structured error logging.Best Practices
Use typed error assertions
Use
errors.As() to match specific error types and handle them differently: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.Use exponential backoff
The default
RetryConfig uses exponential backoff with a base of 2.0. Avoid fixed short delays that could overwhelm the API during outages.