# `Bourse.RateLimiter.State`
[🔗](https://github.com/ZenHive/bourse/blob/main/lib/bourse/rate_limiter/state.ex#L1)

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

# `all`

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

Returns all rate limit entries for an exchange.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

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

Starts the State GenServer.

# `status`

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

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

# `status`

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

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

# `status`

```elixir
@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`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
