Bourse.RateLimiter.State (bourse v0.1.0)

Copy Markdown View Source

ETS-backed store for rate limit status across exchanges.

Stores the latest Bourse.RateLimiter.Info from each exchange response, keyed by {exchange_id, api_key | :public, bucket_axis}. This allows consumers to query current rate limit pressure at any time.

Architecture

A GenServer owns the ETS table (OTP-idiomatic -- handles restarts cleanly). The table is :public with read_concurrency: true so any process can read without going through the GenServer.

Usage

case Bourse.RateLimiter.State.status("binance") do
  %Info{remaining: remaining} -> remaining
  nil -> :unknown
end

Summary

Functions

Returns all rate limit entries for an exchange.

Returns a specification to start this module under a supervisor.

Starts the State GenServer.

Returns the latest rate limit info for an exchange's public endpoints.

Returns the latest rate limit info for a specific exchange + credential key.

Returns the latest rate limit info for a specific exchange + credential + bucket axis.

Updates the rate limit info for a given key.

Functions

all(exchange_id)

@spec all(String.t()) :: [Bourse.RateLimiter.Info.t()]

Returns all rate limit entries for an exchange.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the State GenServer.

status(exchange_id)

@spec status(String.t()) :: Bourse.RateLimiter.Info.t() | nil

Returns the latest rate limit info for an exchange's public endpoints.

status(exchange_id, credential_key)

@spec status(String.t(), term()) :: Bourse.RateLimiter.Info.t() | nil

Returns the latest rate limit info for a specific exchange + credential key.

status(exchange_id, credential_key, axis)

@spec status(String.t(), term(), String.t()) :: Bourse.RateLimiter.Info.t() | nil

Returns the latest rate limit info for a specific exchange + credential + bucket axis.

update(key, info)

@spec update(
  {String.t(), term()} | {String.t(), term(), String.t()},
  Bourse.RateLimiter.Info.t()
) ::
  :ok

Updates the rate limit info for a given key.

Key is {exchange_id, api_key | :public, bucket_axis}. Legacy two-part keys are normalized to the "request" axis.