> ## Documentation Index
> Fetch the complete documentation index at: https://krono.fabianpiper.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# useOrderbookConfig

> Hook for accessing and modifying the orderbook configuration.
Provides reactive state for all configuration parameters and methods to update them.


<Note>
  This hook requires the `OrderbookProvider` to be present in your component tree to provide the underlying `Orderbook` instance.
</Note>

## Import

```ts theme={null}
import { useOrderbookConfig } from '@krono/hooks'
```

## Usage

```tsx theme={null}
import { useOrderbookConfig } from '@krono/hooks'

function OrderbookSettings() {
  const { symbol, limit, setLimit } = useOrderbookConfig();

  return (
    <div>
      <h3>Configuring: {symbol}</h3>
      <label>Visible Levels: {limit}</label>
      <input
        type="range"
        min="1"
        max="100"
        value={limit}
        onChange={(e) => setLimit(Number(e.target.value))}
      />
    </div>
  );
}
```

***

## Parameters

This hook does not accept any parameters. It automatically connects to the `Orderbook` instance provided by the nearest context provider.

***

## Return Type

### State

<ResponseField name="symbol" type="string">
  The current trading pair symbol (e.g., "BTC/USD").
</ResponseField>

<ResponseField name="limit" type="number" default={25}>
  The maximum number of visible price levels returned in the data updates.
</ResponseField>

<ResponseField name="depth" type="10 | 25 | 100 | 500 | 1000" default={500}>
  The subscription depth requested from the Kraken WebSocket.
</ResponseField>

<ResponseField name="groupingOptions" type="number[]"> A generated list of 9 user-friendly grouping steps (1x, 2x, 5x, 10x... of tickSize). </ResponseField>

<ResponseField name="spreadGrouping" type="number" default={0.1}>
  The step size for price grouping (aggregation). Defaults to 0 (no grouping).
</ResponseField>

<ResponseField name="throttleMs" type="number | undefined" default={1_000}>
  The interval in milliseconds used to throttle outgoing data updates.
</ResponseField>

<ResponseField name="debounceMs" type="number | undefined">
  The interval in milliseconds used to debounce outgoing data updates.
</ResponseField>

<ResponseField name="historyEnabled" type="boolean" default={true}>
  Whether the instance is currently recording historical snapshots.
</ResponseField>

<ResponseField name="maxHistoryLength" type="number" default={86_400}>
  The maximum number of snapshots stored in the history buffer.
</ResponseField>

<ResponseField name="debug" type="boolean" default={false}>
  Whether verbose logging is enabled for the orderbook instance.
</ResponseField>

### Actions

<ResponseField name="setSymbol" type="(v: string) => void">
  Updates the trading pair. **Note:** This will clear existing data and trigger a new WebSocket subscription.
</ResponseField>

<ResponseField name="setDepth" type="(v: 10 | 25 | 100 | 500 | 1000) => void">
  Updates the Kraken subscription depth. Triggers a WebSocket re-subscription.
</ResponseField>

<ResponseField name="setLimit" type="(v: number) => void">
  Adjusts the number of levels filtered from the local cache. Does not trigger a re-subscription.
</ResponseField>

<ResponseField name="setTickSize" type="(v: number) => void"> Updates the base increment. This regenerates the groupingOptions. </ResponseField>

<ResponseField name="setSpreadGrouping" type="(v: number) => void"> Updates the price aggregation step size.</ResponseField>

<ResponseField name="setThrottle" type="(v: number | undefined) => void">
  Configures the throttle interval for the update pipeline.
</ResponseField>

<ResponseField name="setDebounce" type="(v: number | undefined) => void">
  Configures the debounce interval for the update pipeline.
</ResponseField>

<ResponseField name="setHistoryEnabled" type="(v: boolean) => void">
  Toggles the recording of historical snapshots.
</ResponseField>

<ResponseField name="setMaxHistoryLength" type="(v: number) => void">
  Resizes the internal history buffer.
</ResponseField>

## Examples

### Performance Tuning

Switch between throttling for high-frequency updates or debouncing for a "calmer" UI experience.

```tsx theme={null}
function PerformanceControls() {
  const { throttleMs, setThrottle } = useOrderbookConfig();

  return (
    <button onClick={() => setThrottle(throttleMs === 100 ? undefined : 100)}>
      {throttleMs ? 'Disable Throttling' : 'Enable 100ms Throttle'}
    </button>
  );
}
```

### Depth vs. Limit Management

`depth` controls how much data we request from Kraken, while `limit` controls how much we actually show in the UI.

<Tip>
  For the best performance, keep `limit` smaller than or equal to `depth`. Setting a `limit` of 10 while requesting a `depth` of 1000 provides a smooth experience when prices move quickly outside the visible range.
</Tip>

```tsx theme={null}
function DepthSettings() {
  const { depth, setDepth, limit, setLimit } = useOrderbookConfig();

  return (
    <div className="flex gap-4">
      <select value={depth} onChange={(e) => setDepth(Number(e.target.value))}>
        {[10, 25, 100, 500, 1000].map(d => (
          <option key={d} value={d}>Fetch {d} levels</option>
        ))}
      </select>

      <input
        type="number"
        value={limit}
        onChange={(e) => setLimit(Number(e.target.value))}
        placeholder="Show N levels"
      />
    </div>
  );
}
```

***

## Related

<CardGroup cols={2}>
  <Card title="Orderbook Core" icon="toy-brick" href="/docs/core/api/classes/Orderbook">
    Explore the underlying class logic and event emitters.
  </Card>

  <Card title="useOrderbookConnection" icon="book-open" href="/docs/hooks/api/useOrderbook">
    Access and modify the orderbook websocket connection.
  </Card>

  <Card title="useAssetPairs" icon="text-search" href="/docs/hooks/api/useAssetPairs">
    Find valid symbols to pass to `setSymbol`.
  </Card>

  <Card title="Kraken API" icon="link" href="https://docs.kraken.com/api/docs/websocket-v2/book">
    Explore the `book` channel streams level 2 order book docs.
  </Card>
</CardGroup>
