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

# Book (Level 2)

> Subscribe to level 2 order book data with aggregated quantities at each price level

<div className="api-banner">
  <span className="api-protocol ws">WSS</span>
  <span className="api-detail">ws.kraken.com/v2</span>
  <span className="api-tag">book</span>
</div>

The `book` channel streams level 2 (L2) order book. It describes the individual price levels in the book with aggregated order quantities at each level.

Subscriptions to this channel can be made for multiple symbols at once by specifying a list of pairs in the `symbol`.

For more detail on maintaining the order book and generating a checksum, see [guide](/exchange/guides/websockets/book-checksum-v2).

## Subscribe

<Tabs>
  <Tab title="Request">
    <ResponseField name="method" type="string" required>
      Value: `subscribe`
    </ResponseField>

    <ResponseField name="params" type="object" required>
      <Expandable title="properties" defaultOpen>
        <ResponseField name="channel" type="string" required>
          Value: `book`
        </ResponseField>

        <ResponseField name="symbol" type="string[]" required>
          <span className="field-attr">Example:</span> `["BTC/USD", "MATIC/GBP"]`

          A list of currency pairs.
        </ResponseField>

        <ResponseField name="depth" type="integer">
          <span className="field-attr">One of:</span> `10`, `25`, `100`, `500`, `1000`<br />
          <span className="field-attr">Default:</span> `10`

          The number of price levels to be received.
        </ResponseField>

        <ResponseField name="snapshot" type="boolean">
          <span className="field-attr">One of:</span> `true`, `false`<br />
          <span className="field-attr">Default:</span> `true`

          Request a snapshot after subscribing.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="req_id" type="integer">
      Optional client originated request identifier sent as acknowledgment in the response.
    </ResponseField>
  </Tab>

  <Tab title="Response">
    There is a separate acknowledgement response for each symbol in the subscription list.

    <ResponseField name="method" type="string" required>
      Value: `subscribe`
    </ResponseField>

    <ResponseField name="result" type="object">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="channel" type="string" required>
          Value: `book`
        </ResponseField>

        <ResponseField name="symbol" type="string" required>
          <span className="field-attr">Example:</span> `"BTC/USD"`

          The currency pair associated with this subscription.
        </ResponseField>

        <ResponseField name="depth" type="integer">
          <span className="field-attr">One of:</span> `10`, `25`, `100`, `500`, `1000`

          Specifies the number of price levels (in each side of the book) to be received.
        </ResponseField>

        <ResponseField name="snapshot" type="boolean">
          Indicates if a snapshot is requested.
        </ResponseField>

        <ResponseField name="warnings" type="string[]">
          An advisory message, highlighting deprecated fields or upcoming changes to the channel.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="success" type="boolean">
      Indicates if the request was successfully processed by the engine. One of: `true`, `false`
    </ResponseField>

    <ResponseField name="error" type="string">
      Error message. Condition: if `success` is `false`.
    </ResponseField>

    <ResponseField name="time_in" type="string">
      The timestamp when the subscription was received on the wire, just prior to parsing data. Format: RFC3339. Example: `2022-12-25T09:30:59.123456Z`
    </ResponseField>

    <ResponseField name="time_out" type="string">
      The timestamp when the acknowledgement was sent on the wire, just prior to transmitting data. Format: RFC3339. Example: `2022-12-25T09:30:59.123456Z`
    </ResponseField>

    <ResponseField name="req_id" type="integer">
      Optional client originated request identifier sent as acknowledgment in the response.
    </ResponseField>
  </Tab>
</Tabs>

## Snapshot

The returned snapshot data contains the specified number of bids and asks for the symbol including a CRC32 checksum of the top 10 bids and asks.

<ResponseField name="channel" type="string">
  Value: `book`
</ResponseField>

<ResponseField name="type" type="string">
  <span className="field-attr">One of:</span> `snapshot`
</ResponseField>

<ResponseField name="data" type="object[]">
  <Expandable title="properties" defaultOpen>
    <ResponseField name="asks" type="object[]">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="price" type="float">The ask price.</ResponseField>
        <ResponseField name="qty" type="float">The ask quantity.</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="bids" type="object[]">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="price" type="float">The bid price.</ResponseField>
        <ResponseField name="qty" type="float">The bid quantity.</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="checksum" type="integer">CRC32 checksum for the top 10 bids and asks.</ResponseField>

    <ResponseField name="symbol" type="string">
      <span className="field-attr">Example:</span> `"BTC/USD"`

      The symbol of the currency pair.
    </ResponseField>

    <ResponseField name="timestamp" type="string">
      <span className="field-attr">Format:</span> RFC3339<br />
      <span className="field-attr">Example:</span> `2022-12-25T09:30:59.123456Z`

      The timestamp of the order book snapshot.
    </ResponseField>
  </Expandable>
</ResponseField>

## Update

The data contains the updates of the bids and asks for the relevant symbol including a CRC32 checksum of the top 10 bids and asks.

Note, it is possible to have multiple updates to the same price level in a single update message. Updates should always be processed in sequence.

<ResponseField name="channel" type="string">
  Value: `book`
</ResponseField>

<ResponseField name="type" type="string">
  <span className="field-attr">One of:</span> `update`
</ResponseField>

<ResponseField name="data" type="object[]">
  <Expandable title="properties" defaultOpen>
    <ResponseField name="asks" type="object[]">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="price" type="float">The ask price.</ResponseField>
        <ResponseField name="qty" type="float">The ask quantity.</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="bids" type="object[]">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="price" type="float">The bid price.</ResponseField>
        <ResponseField name="qty" type="float">The bid quantity.</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="checksum" type="integer">CRC32 checksum for the top 10 bids and asks.</ResponseField>

    <ResponseField name="symbol" type="string">
      <span className="field-attr">Example:</span> `"BTC/USD"`

      The symbol of the currency pair.
    </ResponseField>

    <ResponseField name="timestamp" type="string">
      <span className="field-attr">Format:</span> RFC3339<br />
      <span className="field-attr">Example:</span> `2022-12-25T09:30:59.123456Z`

      The book order update timestamp.
    </ResponseField>
  </Expandable>
</ResponseField>

## Unsubscribe

<Tabs>
  <Tab title="Request">
    <ResponseField name="method" type="string" required>
      Value: `unsubscribe`
    </ResponseField>

    <ResponseField name="params" type="object" required>
      <Expandable title="properties" defaultOpen>
        <ResponseField name="channel" type="string" required>
          Value: `book`
        </ResponseField>

        <ResponseField name="symbol" type="string[]" required>
          <span className="field-attr">Example:</span> `["BTC/USD", "MATIC/GBP"]`

          A list of currency pairs.
        </ResponseField>

        <ResponseField name="depth" type="integer">
          <span className="field-attr">One of:</span> `10`, `25`, `100`, `500`, `1000`

          The number of price levels to be unsubscribed.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="req_id" type="integer">
      Optional client originated request identifier sent as acknowledgment in the response.
    </ResponseField>
  </Tab>

  <Tab title="Response">
    There is a separate acknowledgement response for each symbol in the unsubscription list.

    <ResponseField name="method" type="string" required>
      Value: `unsubscribe`
    </ResponseField>

    <ResponseField name="result" type="object">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="channel" type="string" required>
          Value: `book`
        </ResponseField>

        <ResponseField name="symbol" type="string" required>
          <span className="field-attr">Example:</span> `"BTC/USD"`

          The currency pair associated with this subscription.
        </ResponseField>

        <ResponseField name="depth" type="integer">
          <span className="field-attr">One of:</span> `10`, `25`, `100`, `500`, `1000`

          Specifies the number of price levels (in each side of the book) to be unsubscribed.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="success" type="boolean">
      Indicates if the request was successfully processed by the engine. One of: `true`, `false`
    </ResponseField>

    <ResponseField name="error" type="string">
      Error message. Condition: if `success` is `false`.
    </ResponseField>

    <ResponseField name="time_in" type="string">
      The timestamp when the subscription was received on the wire, just prior to parsing data. Format: RFC3339. Example: `2022-12-25T09:30:59.123456Z`
    </ResponseField>

    <ResponseField name="time_out" type="string">
      The timestamp when the acknowledgement was sent on the wire, just prior to transmitting data. Format: RFC3339. Example: `2022-12-25T09:30:59.123456Z`
    </ResponseField>

    <ResponseField name="req_id" type="integer">
      Optional client originated request identifier sent as acknowledgment in the response.
    </ResponseField>
  </Tab>
</Tabs>

<Panel>
  <CodeGroup>
    ```json Subscribe Request theme={null}
    {
        "method": "subscribe",
        "params": {
            "channel": "book",
            "symbol": [
                "ALGO/USD",
                "MATIC/USD"
            ]
        }
    }
    ```

    ```json Subscribe Response theme={null}
    {
        "method": "subscribe",
        "result": {
            "channel": "book",
            "depth": 10,
            "snapshot": true,
            "symbol": "ALGO/USD"
        },
        "success": true,
        "time_in": "2023-10-06T17:35:55.219022Z",
        "time_out": "2023-10-06T17:35:55.219067Z"
    }

    {
        "method": "subscribe",
        "result": {
            "channel": "book",
            "depth": 10,
            "snapshot": true,
            "symbol": "MATIC/USD"
        },
        "success": true,
        "time_in": "2023-10-06T17:35:55.219022Z",
        "time_out": "2023-10-06T17:35:55.219067Z"
    }
    ```
  </CodeGroup>

  <CodeGroup>
    ```json Snapshot theme={null}
    {
        "channel": "book",
        "type": "snapshot",
        "data": [
            {
                "symbol": "MATIC/USD",
                "bids": [
                    {
                        "price": 0.5666,
                        "qty": 4831.75496356
                    },
                    {
                        "price": 0.5665,
                        "qty": 6658.22734739
                    },
                    {
                        "price": 0.5664,
                        "qty": 18724.91513344
                    },
                    {
                        "price": 0.5663,
                        "qty": 11563.92544914
                    },
                    {
                        "price": 0.5662,
                        "qty": 14006.65365711
                    },
                    {
                        "price": 0.5661,
                        "qty": 17454.85679807
                    },
                    {
                        "price": 0.566,
                        "qty": 18097.1547
                    },
                    {
                        "price": 0.5659,
                        "qty": 33644.89175666
                    },
                    {
                        "price": 0.5658,
                        "qty": 148.3464
                    },
                    {
                        "price": 0.5657,
                        "qty": 606.70854372
                    }
                ],
                "asks": [
                    {
                        "price": 0.5668,
                        "qty": 4410.79769741
                    },
                    {
                        "price": 0.5669,
                        "qty": 4655.40412487
                    },
                    {
                        "price": 0.567,
                        "qty": 49844.89424998
                    },
                    {
                        "price": 0.5671,
                        "qty": 24306.41678
                    },
                    {
                        "price": 0.5672,
                        "qty": 29783.25223475
                    },
                    {
                        "price": 0.5673,
                        "qty": 57234.71239278
                    },
                    {
                        "price": 0.5674,
                        "qty": 45065.04744
                    },
                    {
                        "price": 0.5675,
                        "qty": 5912.76380354
                    },
                    {
                        "price": 0.5676,
                        "qty": 42514.92434778
                    },
                    {
                        "price": 0.5677,
                        "qty": 36304.0847022
                    }
                ],
                "checksum": 2439117997,
                "timestamp": "2023-10-06T17:35:55.440295Z"
            }
        ]
    }
    ```

    ```json Update theme={null}
    {
        "channel": "book",
        "type": "update",
        "data": [
            {
                "symbol": "MATIC/USD",
                "bids": [
                    {
                        "price": 0.5657,
                        "qty": 1098.3947558
                    }
                ],
                "asks": [],
                "checksum": 2114181697,
                "timestamp": "2023-10-06T17:35:55.440295Z"
            }
        ]
    }
    ```
  </CodeGroup>

  <CodeGroup>
    ```json Unsubscribe Request theme={null}
    {
        "method": "unsubscribe",
        "params": {
            "channel": "book",
            "symbol": [
                "ALGO/USD",
                "MATIC/USD"
            ]
        }
    }
    ```

    ```json Unsubscribe Response theme={null}
    {
        "method": "unsubscribe",
        "result": {
            "channel": "book",
            "depth": 10,
            "snapshot": true,
            "symbol": "ALGO/USD"
        },
        "success": true,
        "time_in": "2023-10-06T17:35:55.219022Z",
        "time_out": "2023-10-06T17:35:55.219067Z"
    }

    {
        "method": "unsubscribe",
        "result": {
            "channel": "book",
            "depth": 10,
            "snapshot": true,
            "symbol": "MATIC/USD"
        },
        "success": true,
        "time_in": "2023-10-06T17:35:55.219022Z",
        "time_out": "2023-10-06T17:35:55.219067Z"
    }
    ```
  </CodeGroup>
</Panel>
