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

# L2 book stream

> Receive complete finalized order-book snapshots on a fixed cadence.

```text theme={null}
l2Book@f@<coalesceMs>
```

This market-scoped snapshot stream sends the current finalized book when the
subscription starts and then publishes complete snapshots on the requested
cadence. It does not use a replay cursor.

## Subscribe

```json theme={null}
{
  "op": "sub",
  "id": 3,
  "t": "l2Book@f@500",
  "m": "0x8121EE960066e4344A213F9aC7502395502aEe7a",
  "feedEpoch": 0,
  "n": 20,
  "g": "sf",
  "sf": 5,
  "mt": 2,
  "e": false
}
```

`n` is depth per side from `1` through `200`. Grouping `g` is `none`, `tick`,
or `sf`. Use `tk` with tick grouping, `sf` and optional `mt` with significant
figures, and `e=true` for active/passive decomposition.

## Decoded event

The shape below is the inner `message` returned by `decodeExchangeWsEnvelope`
or `decodeExchangeWsMessage`. Every binary socket message also carries an outer
`id: bigint`, matching your subscription ID. Use it to route snapshots, replay,
and live updates. See [binary subscription envelopes](/api/exchange/websocket#binary-subscription-envelope).

```ts theme={null}
type ExchangeWsL2Grouping =
  | { kind: "none" }
  | { kind: "nativeTick"; tickSize: bigint }
  | {
      kind: "significantFigures";
      figures: number;
      mantissa: number | null;
    };

interface ExchangeWsCompactL2Level {
  price: bigint;
  totalBase: bigint;
}

interface ExchangeWsExtendedL2Level extends ExchangeWsCompactL2Level {
  activeBase: bigint;
  passiveBase: bigint;
  activeOrderCount: number;
}

interface ExchangeWsL2BookFrameBase {
  wireVersion: 1;
  feedEpoch: bigint;
  view: "finalized";
  kind: "l2Book";
  marketAddress: string;
  marketSeq: bigint;
  globalSeq: bigint;
  stateHead: { blockNumber: bigint; blockId: string };
  durationMs: bigint;
  maxDepthPerSide: number;
  grouping: ExchangeWsL2Grouping;
}

type ExchangeWsL2BookFrame =
  | (ExchangeWsL2BookFrameBase & {
      levelFormat: "compact";
      bids: ExchangeWsCompactL2Level[];
      asks: ExchangeWsCompactL2Level[];
    })
  | (ExchangeWsL2BookFrameBase & {
      levelFormat: "extended";
      bids: ExchangeWsExtendedL2Level[];
      asks: ExchangeWsExtendedL2Level[];
    });
```

Bids are ordered high to low and asks low to high. Prices are native pp integers; base quantities remain native integers in market size precision.
The decoder performs no scaling. Native tick grouping keeps `tickSize` in protocol ticks.


## AsyncAPI

````yaml api/exchange/asyncapi.yaml l2Book
id: l2Book
title: Subscribe to L2 book snapshots
description: Receive complete finalized order-book snapshots on a fixed cadence.
servers:
  - id: mainnet
    protocol: wss
    host: gateway.mainnet.kuru.io
    bindings: []
    variables: []
  - id: testnet
    protocol: wss
    host: gateway.testnet.kuru.io
    bindings: []
    variables: []
address: /ws
parameters: []
bindings: []
operations:
  - &ref_1
    id: subscribeL2Book
    title: Subscribe l2 book
    type: receive
    messages:
      - &ref_2
        id: request
        contentType: application/json
        payload:
          - name: l2Book@f subscription
            type: object
            properties:
              - name: op
                type: string
                enumValues:
                  - sub
                required: true
              - name: id
                type: integer
                description: >-
                  JSON integer restricted to JavaScript's exact safe-integer
                  range.
                required: true
              - name: t
                type: string
                required: true
              - name: m
                type: string
                description: Lowercase 20-byte market contract address.
                required: true
              - name: feedEpoch
                type: integer
                description: Feed namespace. Required when seq is supplied.
                required: false
              - name: 'n'
                type: integer
                required: false
              - name: g
                type: string
                enumValues:
                  - none
                  - tick
                  - sf
                required: false
              - name: tk
                type: integer
                required: false
              - name: sf
                type: integer
                description: Required with g=sf. Values outside 2 through 5 are rejected.
                required: false
              - name: mt
                type: integer
                description: Optional mantissa bucket. Valid only when g=sf and sf=5.
                enumValues:
                  - 1
                  - 2
                  - 5
                required: false
              - name: e
                type: boolean
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          additionalProperties: false
          required:
            - op
            - id
            - t
            - m
          allOf:
            - if:
                properties:
                  g:
                    const: tick
                required:
                  - g
                x-parser-schema-id: <anonymous-schema-21>
              then:
                required:
                  - tk
                not:
                  anyOf:
                    - required:
                        - sf
                      x-parser-schema-id: <anonymous-schema-24>
                    - required:
                        - mt
                      x-parser-schema-id: <anonymous-schema-25>
                  x-parser-schema-id: <anonymous-schema-23>
                x-parser-schema-id: <anonymous-schema-22>
              x-parser-schema-id: <anonymous-schema-20>
            - if:
                properties:
                  g:
                    const: sf
                required:
                  - g
                x-parser-schema-id: <anonymous-schema-27>
              then:
                required:
                  - sf
                not:
                  required:
                    - tk
                  x-parser-schema-id: <anonymous-schema-29>
                x-parser-schema-id: <anonymous-schema-28>
              x-parser-schema-id: <anonymous-schema-26>
            - if:
                properties:
                  g:
                    const: sf
                  sf:
                    const: 5
                required:
                  - g
                  - sf
                x-parser-schema-id: <anonymous-schema-31>
              else:
                not:
                  required:
                    - mt
                  x-parser-schema-id: <anonymous-schema-33>
                x-parser-schema-id: <anonymous-schema-32>
              x-parser-schema-id: <anonymous-schema-30>
            - if:
                anyOf:
                  - properties:
                      g:
                        const: none
                    required:
                      - g
                    x-parser-schema-id: <anonymous-schema-36>
                  - not:
                      required:
                        - g
                      x-parser-schema-id: <anonymous-schema-38>
                    x-parser-schema-id: <anonymous-schema-37>
                x-parser-schema-id: <anonymous-schema-35>
              then:
                not:
                  anyOf:
                    - required:
                        - tk
                      x-parser-schema-id: <anonymous-schema-41>
                    - required:
                        - sf
                      x-parser-schema-id: <anonymous-schema-42>
                    - required:
                        - mt
                      x-parser-schema-id: <anonymous-schema-43>
                  x-parser-schema-id: <anonymous-schema-40>
                x-parser-schema-id: <anonymous-schema-39>
              x-parser-schema-id: <anonymous-schema-34>
          properties:
            op:
              type: string
              enum:
                - sub
              x-parser-schema-id: <anonymous-schema-11>
            id: &ref_0
              type: integer
              minimum: 0
              maximum: 9007199254740991
              description: >-
                JSON integer restricted to JavaScript's exact safe-integer
                range.
              x-parser-schema-id: ControlInteger
            t:
              type: string
              pattern: ^l2Book@f@[1-9][0-9]*$
              x-parser-schema-id: <anonymous-schema-12>
            m:
              type: string
              pattern: ^0x[0-9a-f]{40}$
              description: Lowercase 20-byte market contract address.
              x-parser-schema-id: MarketAddress
            feedEpoch:
              allOf:
                - *ref_0
              description: Feed namespace. Required when seq is supplied.
              x-parser-schema-id: FeedEpoch
            'n':
              type: integer
              minimum: 1
              maximum: 200
              default: 20
              x-parser-schema-id: <anonymous-schema-13>
            g:
              type: string
              enum:
                - none
                - tick
                - sf
              default: none
              x-parser-schema-id: <anonymous-schema-14>
            tk:
              allOf:
                - *ref_0
                - minimum: 1
                  x-parser-schema-id: <anonymous-schema-16>
              x-parser-schema-id: <anonymous-schema-15>
            sf:
              type: integer
              minimum: 2
              maximum: 5
              description: Required with g=sf. Values outside 2 through 5 are rejected.
              x-parser-schema-id: <anonymous-schema-17>
            mt:
              type: integer
              enum:
                - 1
                - 2
                - 5
              description: Optional mantissa bucket. Valid only when g=sf and sf=5.
              x-parser-schema-id: <anonymous-schema-18>
            e:
              type: boolean
              default: false
              x-parser-schema-id: <anonymous-schema-19>
          x-parser-schema-id: L2BookSubscription
        title: l2Book@f subscription
        example: |-
          {
            "op": "sub",
            "id": 3,
            "t": "l2Book@f@500",
            "m": "0x8121EE960066e4344A213F9aC7502395502aEe7a",
            "feedEpoch": 0,
            "n": 20,
            "g": "sf",
            "sf": 5,
            "mt": 2,
            "e": false
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: request
    bindings: []
    extensions:
      - id: x-parser-unique-object-id
        value: l2Book
sendOperations:
  - *ref_1
receiveOperations: []
sendMessages:
  - *ref_2
receiveMessages: []
extensions:
  - id: x-parser-unique-object-id
    value: l2Book
securitySchemes: []

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.