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

> Bootstrap, replay, and follow finalized order-book changes.

```text theme={null}
l2Delta@f
```

This is a market-scoped, replayable stream. Its cursor is
`(feedEpoch, marketSeq)`.

Without `seq`, the stream sends a finalized L2 snapshot, replays retained deltas
after that snapshot, and then joins live updates. With `seq`, replay begins
strictly after the supplied cursor and no bootstrap snapshot is sent.

## Subscribe

```json theme={null}
{
  "op": "sub",
  "id": 1,
  "t": "l2Delta@f",
  "m": "0x8121EE960066e4344A213F9aC7502395502aEe7a",
  "feedEpoch": 0,
  "seq": 1022
}
```

`m` is required. `seq` is optional and must be greater than zero when supplied.
`feedEpoch` is required whenever `seq` is present. Coalescing durations and L2
formatting options are not accepted.

## 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}
interface ExchangeWsL2DeltaFrame {
  wireVersion: 1;
  feedEpoch: bigint;
  view: "finalized";
  kind: "l2Delta";
  marketAddress: string;
  marketSeq: bigint;
  previousMarketSeq: bigint | null;
  globalSeq: bigint;
  sourceBlock: { blockNumber: bigint; blockId: string };
  updates: Array<{
    side: "buy" | "sell";
    price: bigint;
    totalBaseAfter: bigint;
    activeBaseAfter: bigint;
    passiveBaseAfter: bigint;
    activeOrderCountAfter: number;
  }>;
}
```

`price` is an integer in market price precision (pp). The base fields use the
market's native size precision; `totalBaseAfter === 0n` deletes the level.

`previousMarketSeq` is the previous publication in this exact market, view,
and topic stream. A zero wire value decodes to `null`. For a replay requested
after `R`, the first frame is a valid sparse bridge when `marketSeq > R` and
`previousMarketSeq` is `null` or at most `R`; every later frame must point
exactly to the last accepted `marketSeq`.


## AsyncAPI

````yaml api/exchange/asyncapi.yaml l2Delta
id: l2Delta
title: Subscribe to L2 deltas
description: Bootstrap, replay, and follow finalized order-book changes for one market.
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: subscribeL2Delta
    title: Subscribe l2 delta
    type: receive
    messages:
      - &ref_2
        id: request
        contentType: application/json
        payload:
          - name: l2Delta@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
                enumValues:
                  - l2Delta@f
                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: seq
                type: integer
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          additionalProperties: false
          required:
            - op
            - id
            - t
            - m
          allOf:
            - if:
                required:
                  - seq
                x-parser-schema-id: <anonymous-schema-4>
              then:
                required:
                  - feedEpoch
                x-parser-schema-id: <anonymous-schema-5>
              x-parser-schema-id: <anonymous-schema-3>
          properties:
            op:
              type: string
              enum:
                - sub
              x-parser-schema-id: <anonymous-schema-1>
            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
              enum:
                - l2Delta@f
              x-parser-schema-id: <anonymous-schema-2>
            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
            seq:
              allOf:
                - *ref_0
              minimum: 1
              x-parser-schema-id: ReplaySequence
          x-parser-schema-id: L2DeltaSubscription
        title: l2Delta@f subscription
        example: |-
          {
            "op": "sub",
            "id": 1,
            "t": "l2Delta@f",
            "m": "0x8121EE960066e4344A213F9aC7502395502aEe7a",
            "feedEpoch": 0,
            "seq": 1022
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: request
    bindings: []
    extensions:
      - id: x-parser-unique-object-id
        value: l2Delta
sendOperations:
  - *ref_1
receiveOperations: []
sendMessages:
  - *ref_2
receiveMessages: []
extensions:
  - id: x-parser-unique-object-id
    value: l2Delta
securitySchemes: []

````

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