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

> Subscribe to order book levels (Level 2)

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

Order book levels. On subscription, a snapshot is published at the specified depth, followed by level updates. Subscription depth options are 10, 25, 100, 500, or 1000 levels per side.

## Subscribe

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

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

      The currency pairs for this request.
    </ResponseField>

    <ResponseField name="subscription" type="object">
      <Expandable title="properties" defaultOpen>
        <ResponseField name="name" type="string" required>
          Value: `book`
        </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`

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

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

  <Tab title="Response">
    The subscription status is returned via the [subscriptionStatus](/exchange/api-reference/spot-websocket-v1/subscriptionstatus) message.
  </Tab>
</Tabs>

## Snapshot

Note, there is no checksum on the snapshot.

<ResponseField name="" type="array">
  <Expandable title="elements" defaultOpen>
    <ResponseField name="[0] channel_id" type="integer" deprecated>
      <span className="field-attr">Deprecated:</span> use `channelName` and `pair`

      Channel identifier.
    </ResponseField>

    <ResponseField name="[1] book" type="object">
      <Expandable title="properties">
        <ResponseField name="as" type="array">
          Ask price levels, ascending from best ask.

          <Expandable title="elements">
            <ResponseField name="level" type="array">
              <Expandable title="elements">
                <ResponseField name="[0] price" type="string">The price of this level.</ResponseField>
                <ResponseField name="[1] volume" type="string">Price level volume, for updates volume = 0 for level removal/deletion.</ResponseField>

                <ResponseField name="[2] timestamp" type="string">
                  <span className="field-attr">Format:</span> Epoch Seconds<br />
                  <span className="field-attr">Example:</span> `1534614248.456738`

                  Timestamp when the level last updated.
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="bs" type="array">
          Bid price levels, ascending from best bid.

          <Expandable title="elements">
            <ResponseField name="level" type="array">
              <Expandable title="elements">
                <ResponseField name="[0] price" type="string">Price level.</ResponseField>
                <ResponseField name="[1] volume" type="string">Price level volume, for updates volume = 0 for level removal/deletion.</ResponseField>

                <ResponseField name="[2] timestamp" type="string">
                  <span className="field-attr">Format:</span> Epoch Seconds<br />
                  <span className="field-attr">Example:</span> `1534614248.456738`

                  Timestamp when the level last updated.
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="[2] pair" type="string">
      <span className="field-attr">Example:</span> `"BTC/USD"`

      The symbol of the currency pair.
    </ResponseField>

    <ResponseField name="[3] channel_name" type="string">
      Value: `book-[depth]`
    </ResponseField>
  </Expandable>
</ResponseField>

## Update

<ResponseField name="" type="array">
  <Expandable title="elements" defaultOpen>
    <ResponseField name="[0] channel_id" type="integer" deprecated>
      <span className="field-attr">Deprecated:</span> use `channelName` and `pair`

      Channel identifier.
    </ResponseField>

    <ResponseField name="[1] book" type="object">
      <Expandable title="properties">
        <ResponseField name="a" type="array">
          Ask price levels.

          <Expandable title="elements">
            <ResponseField name="level" type="array">
              <Expandable title="elements">
                <ResponseField name="[0] price" type="string">The price for this level.</ResponseField>
                <ResponseField name="[1] volume" type="string">The cumulative volume at this price level. If volume is 0, remove level from book.</ResponseField>

                <ResponseField name="[2] timestamp" type="string">
                  <span className="field-attr">Format:</span> Epoch Seconds<br />
                  <span className="field-attr">Example:</span> `1534614248.456738`

                  Timestamp when the level was last updated.
                </ResponseField>

                <ResponseField name="[3] update_type" type="string">
                  <span className="field-attr">One of:</span> `r`<br />
                  <span className="field-attr">Condition:</span> Republish only
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>

          <ResponseField name="c" type="string">
            <span className="field-attr">Example:</span> `"4088505763"`<br />
            <span className="field-attr">Condition:</span> Only present on last update

            Book checksum as a quoted unsigned 32-bit integer.
          </ResponseField>
        </ResponseField>

        <ResponseField name="b" type="array">
          Bid price levels.

          <Expandable title="elements">
            <ResponseField name="level" type="array">
              <Expandable title="elements">
                <ResponseField name="[0] price" type="string">The price for this level.</ResponseField>
                <ResponseField name="[1] volume" type="string">The cumulative volume at this price level. If volume is 0, remove level from book.</ResponseField>

                <ResponseField name="[2] timestamp" type="string">
                  <span className="field-attr">Format:</span> Epoch Seconds<br />
                  <span className="field-attr">Example:</span> `1534614248.456738`

                  Timestamp when the level was last updated.
                </ResponseField>

                <ResponseField name="[3] update_type" type="string">
                  <span className="field-attr">One of:</span> `r`<br />
                  <span className="field-attr">Condition:</span> Republish only
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>

          <ResponseField name="c" type="string">
            <span className="field-attr">Example:</span> `"4088505763"`<br />
            <span className="field-attr">Condition:</span> Only present on last update

            Book checksum as a quoted unsigned 32-bit integer.
          </ResponseField>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="[2] pair" type="string">
      <span className="field-attr">Example:</span> `"BTC/USD"`

      The symbol of the currency pair.
    </ResponseField>

    <ResponseField name="[3] channel_name" type="string">
      Value: `book-[depth]`
    </ResponseField>
  </Expandable>
</ResponseField>

## Unsubscribe

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

    <ResponseField name="pair" type="string[]">
      <span className="field-attr">Example:</span> `["BTC/USD", "MATIC/GBP"]`<br />
      <span className="field-attr">Condition:</span> All channels which support pair subscriptions

      The currency pairs to unsubscribe.
    </ResponseField>

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

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

        <ResponseField name="depth" type="integer">
          <span className="field-attr">Condition:</span> 'book' channel only

          Unsubscribe to a specific depth.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Tab>

  <Tab title="Response">
    The unsubscription status is returned via the [subscriptionStatus](/exchange/api-reference/spot-websocket-v1/subscriptionstatus) message.
  </Tab>
</Tabs>

<Panel>
  <CodeGroup>
    ```json Subscribe theme={null}
    {
      "event": "subscribe",
      "pair": [
        "XBT/USD",
        "XBT/EUR"
      ],
      "subscription": {
        "name": "book"
      }
    }
    ```
  </CodeGroup>

  <CodeGroup>
    ```json Snapshot theme={null}
    [
      0,
      {
        "as": [
          [
            "5541.30000",
            "2.50700000",
            "1534614248.123678"
          ],
          [
            "5541.80000",
            "0.33000000",
            "1534614098.345543"
          ],
          [
            "5542.70000",
            "0.64700000",
            "1534614244.654432"
          ]
        ],
        "bs": [
          [
            "5541.20000",
            "1.52900000",
            "1534614248.765567"
          ],
          [
            "5539.90000",
            "0.30000000",
            "1534614241.769870"
          ],
          [
            "5539.50000",
            "5.00000000",
            "1534613831.243486"
          ]
        ]
      },
      "book-100",
      "XBT/USD"
    ]
    ```
  </CodeGroup>

  <CodeGroup>
    ```json Update: Asks theme={null}
    [
      1234,
      {
        "a": [
          [
            "5541.30000",
            "2.50700000",
            "1534614248.456738"
          ],
          [
            "5542.50000",
            "0.40100000",
            "1534614248.456738"
          ]
        ],
        "c": "974942666"
      },
      "book-10",
      "XBT/USD"
    ]
    ```

    ```json Update: Bids theme={null}
    [
      1234,
      {
        "b": [
          [
            "5541.30000",
            "0.00000000",
            "1534614335.345903"
          ]
        ],
        "c": "974942666"
      },
      "book-10",
      "XBT/USD"
    ]
    ```

    ```json Update: Bids and Asks theme={null}
    [
      1234,
      {
        "a": [
          [
            "5541.30000",
            "2.50700000",
            "1534614248.456738"
          ],
          [
            "5542.50000",
            "0.40100000",
            "1534614248.456738"
          ]
        ]
      },
      {
        "b": [
          [
            "5541.30000",
            "0.00000000",
            "1534614335.345903"
          ]
        ],
        "c": "974942666"
      },
      "book-10",
      "XBT/USD"
    ]
    ```

    ```json Update: Republish theme={null}
    [
      1234,
      {
        "a": [
          [
            "5541.30000",
            "2.50700000",
            "1534614248.456738",
            "r"
          ],
          [
            "5542.50000",
            "0.40100000",
            "1534614248.456738",
            "r"
          ]
        ],
        "c": "974942666"
      },
      "book-25",
      "XBT/USD"
    ]
    ```
  </CodeGroup>

  <CodeGroup>
    ```json Unsubscribe theme={null}
    {
      "event": "unsubscribe",
      "pair": [
        "XBT/EUR",
        "XBT/USD"
      ],
      "subscription": {
        "name": "book"
      }
    }
    ```
  </CodeGroup>
</Panel>
