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

# Orderbook

> Customize the behavior, performance, and connection logic of the Orderbook.

The `Orderbook` class accepts a configuration object during instantiation. While `symbol` is the only required parameter, you can fine-tune the pipeline, history, and connection settings to match your specific requirements.

## Usage

```ts theme={null}
import { Orderbook } from '@krono/core';

const orderbook = new Orderbook({
  symbol: 'BTC/USD',
  depth: 100,
  limit: 50,
  throttleMs: 100,
  reconnect: {
    enabled: true,
    maxAttempts: 5,
    delayMs: 1000
  }
});
```

## Core Settings

<ParamField body="symbol" type="string" required>
  The trading pair symbol to subscribe to (e.g., `BTC/USD`, `ETH/EUR`).
</ParamField>

<ParamField body="depth" type="number" default="1_000">
  The subscription depth requested from the Kraken WebSocket.

  Allowed values: `10`, `25`, `100`, `500`, `1000`.

  <Note>
    A higher depth increases network traffic. Choose the lowest value that satisfies your `limit` requirement.
  </Note>
</ParamField>

<ParamField body="limit" type="number" default="100">
  The maximum number of price levels (asks/bids) kept in the local memory and exposed in snapshots.

  If `limit` is lower than `depth`, the orderbook will crop the data client-side.
</ParamField>

<ParamField body="tickSize" type="number">
  The minimum price increment allowed for the asset pair. This value is used to generate the valid groupingOptions.
</ParamField>

<ParamField body="spreadGrouping" type="number" default="0">
  Combines price levels into groups of this size. Useful for visualizing the book or reducing noise.

  <Note>
    When the `tickSize` or `symbol` changes, the orderbook automatically resets `spreadGrouping` to match the `tickSize` to ensure the most granular view by default.
  </Note>
</ParamField>

## Pipeline & Performance

<ParamField body="throttleMs" type="number">
  Restricts the frequency of updates. If set, the orderbook will only emit the `DataUpdate` event once every `throttleMs` milliseconds, discarding intermediate updates.
</ParamField>

<ParamField body="debounceMs" type="number">
  Delays the update emission until the orderbook has been stable (received no new messages) for `debounceMs` milliseconds.
</ParamField>

<ParamField body="debug" type="boolean" default="false">
  Enables verbose logging to the console. Useful for diagnosing connection issues or pipeline behavior.
</ParamField>

## History Management

<ParamField body="historyEnabled" type="boolean" default="false">
  When enabled, the orderbook maintains a ring buffer of previous snapshots.
</ParamField>

<ParamField body="maxHistoryLength" type="number">
  The maximum number of historical snapshots to retain in memory. Oldest snapshots are discarded when the limit is reached.
</ParamField>

## Connection & Reconnection

<ParamField body="reconnect" type="object">
  Configuration for the automatic reconnection strategy.

  <Expandable title="properties">
    <ParamField body="enabled" type="boolean">
      Whether to attempt reconnection automatically on disconnect or error.
    </ParamField>

    <ParamField body="maxAttempts" type="number">
      The maximum number of consecutive reconnection attempts before giving up.
    </ParamField>

    <ParamField body="delayMs" type="number">
      The delay in milliseconds between reconnection attempts.
    </ParamField>
  </Expandable>
</ParamField>
