Skip to content

Resilience

Resilience features: retry transport, rate limiting, and request logging.

Classes:

  • KrakenTier

    Kraken account tier, determines rate limit parameters.

  • ResilienceConfig

    Configuration for retry and logging behavior.

  • RetryTransport

    Sync httpx transport that retries on transient network errors.

  • AsyncRetryTransport

    Async httpx transport that retries on transient network errors.

  • RateLimiter

    Caller-controlled token bucket rate limiter matching Kraken's tiers.

Functions:

KrakenTier

Bases: str, Enum

Kraken account tier, determines rate limit parameters.

See https://docs.kraken.com/api/ for tier-specific limits.

ResilienceConfig

Configuration for retry and logging behavior.

Passed to HTTPClient or HTTPAuthenticatedClient at construction time via the resilience keyword argument.

Retry is disabled by default (max_retries=0). Only transient network errors are retried — API-level errors (rate limits, validation) are never retried at the transport layer.

Logging uses Python's stdlib logging module via httpx event hooks. Configure the kraken_connector logger in your application to control output (e.g., with structlog's stdlib integration).

RetryTransport

Bases: BaseTransport

Sync httpx transport that retries on transient network errors.

AsyncRetryTransport

Bases: AsyncBaseTransport

Async httpx transport that retries on transient network errors.

RateLimiter

Caller-controlled token bucket rate limiter matching Kraken's tiers.

Usage::

limiter = RateLimiter.from_tier(KrakenTier.STARTER)

# Sync
with limiter.acquire(cost=1):
    response = get_server_time.sync(client=client)

# Async
async with limiter.async_acquire(cost=2):
    response = await get_trade_history.asyncio(client=client)

The cost parameter supports Kraken's variable token costs: most calls cost 1, but ledger/trade history calls cost 2.

Methods:

  • from_tier

    Create a rate limiter with parameters matching tier.

  • acquire

    Block until cost tokens are available, then yield.

  • async_acquire

    Async version of :meth:acquire.

from_tier classmethod

from_tier(tier)

Create a rate limiter with parameters matching tier.

acquire

acquire(cost=1.0)

Block until cost tokens are available, then yield.

async_acquire async

async_acquire(cost=1.0)

Async version of :meth:acquire.

make_event_hooks

make_event_hooks(config)

Build httpx event_hooks for request/response logging.