Skip to main content

Overview

The SDK provides a typed error hierarchy, a generic retry function with exponential backoff, a RetryableClient wrapper, and pluggable logging — all following idiomatic Go patterns.

Error Types

All API errors implement the error interface and can be inspected using errors.As():

APIError

The base error type for all HTTP errors. Its Error() method returns a formatted string like "API error 401 GET /path: message".

Specialized Error Types

The SDK provides three specialized error types that embed APIError:

OrderValidationError

Client-side validation errors thrown before a request is made:

Common Status Codes

Helper Method

APIError provides an IsAuthError() method to quickly check for authentication issues:

WithRetry (Generic)

The SDK provides a generic WithRetry function that wraps any operation with configurable retry logic using Go generics:

RetryConfig

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 your HttpClient with RetryableClient. This applies retry logic to all API calls made through the client:
The RetryableClient exposes the same request methods as HttpClient (Get, GetRaw, Post, Patch, Delete) and transparently retries on the configured status codes. Use these methods for raw requests that need retry coverage.
Use RetryableClient for automated trading bots that need resilience against transient failures without wrapping every call in WithRetry individually.

Debugging with ConsoleLogger

Enable verbose logging to trace requests, responses, and internal operations:
At 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

Custom Logger

Implement the Logger 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

1

Always check errors

Every SDK method returns error as the last return value. Always check it:
2

Use typed error assertions

Use errors.As() to match specific error types and handle them differently:
3

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.
4

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.
5

Pass context for cancellation

Always pass a context.Context to allow timeouts and cancellation:
6

Use DEBUG logging during development

Enable LogLevelDebug to see the full request/response cycle. Switch to LogLevelInfo or LogLevelWarn in production to reduce noise.