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

# L2 Order Book

> L2 Order Book WebSocket subscription and response reference.

Connect to `wss://mainnet-ws1.bulk.trade`, then send the subscription below. All channels share the same socket; the page name is not a separate endpoint path. The playground sends read-only subscription messages.

Periodic full order book snapshots.

```json Subscribe theme={null}
{
  "method": "subscribe",
  "subscription": [{
    "type": "l2Snapshot",
    "symbol": "BTC-USD",
    "nlevels": 10,
    "aggregation": 0.5
  }]
}
```

```json Response theme={null}
{
  "type": "subscriptionResponse",
  "topics": ["l2snapshot.BTC-USD.10.0.5"]
}
```

```json Update theme={null}
{
  "type": "l2Snapshot",
  "data": {
    "book": {
      "updateType": "snapshot",
      "symbol": "BTC-USD",
      "levels": [
        [
          {"px": 102777.0, "sz": 1.5, "n": 3},
          {"px": 102776.5, "sz": 2.3, "n": 5},
          {"px": 102776.0, "sz": 0.8, "n": 2}
        ],
        [
          {"px": 102780.0, "sz": 2.0, "n": 4},
          {"px": 102780.5, "sz": 1.2, "n": 3},
          {"px": 102781.0, "sz": 1.8, "n": 2}
        ]
      ],
      "timestamp": 1699564800000000000
    }
  },
  "topic": "l2snapshot.BTC-USD.10.0.5"
}
```

**Parameters**:

* `nlevels` (optional): Number of price levels per side
* `aggregation` (optional): Price bucket size in quote currency

**Update Frequency**: Periodic, according to the network endpoint's book-snapshot publication cadence.

**Structure**: `levels[0]` = bids (descending), `levels[1]` = asks (ascending)

`timestamp` is Unix time in **nanoseconds**. Replace the local snapshot in full
on each message. The topic includes `nlevels` and, when supplied alongside
`nlevels`, `aggregation`; use the exact returned topic when unsubscribing.
For example, `nlevels: 20` produces `l2snapshot.BTC-USD.20`. Supply `nlevels`
when using aggregation so each aggregation variant has a distinct topic.

## Connection and Limits

See [connection management](https://docs.bulk.trade/api-reference/ws-connection.md) for reconnect behavior and [public rate limits](https://docs.bulk.trade/api-reference/rate-limits.md) for connection budgets.


## AsyncAPI

````yaml api-reference/asyncapi.yaml l2-orderbook
id: l2-orderbook
title: L2 order book
description: >-
  Periodic full snapshots. Replace both sides. nlevels and aggregation customize
  the snapshot topic; retain the exact acknowledged topic. Connect, then send
  subscribe; unsubscribe uses the acknowledged topic. Unsubscribe using the
  acknowledged topic; see [Connection
  Management](/api-reference/ws-connection#unsubscribe).
servers:
  - id: mainnet
    protocol: wss
    host: mainnet-ws1.bulk.trade
    bindings: []
    variables: []
  - id: testnet
    protocol: wss
    host: exchange-ws1.bulk.trade
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_1
    id: l2-orderbookSubscribe
    title: L2 order book subscribe
    type: receive
    messages:
      - &ref_3
        id: subscribe
        contentType: application/json
        payload:
          - name: L2 order book subscribe
            description: >-
              Schema defaults on this request are playground example prefills,
              not omitted-field defaults accepted by the network endpoint.
            type: object
            properties:
              - name: method
                type: string
                enumValues:
                  - subscribe
                required: true
              - name: subscription
                type: array
                description: >-
                  Playground example prefill. Send the subscription array
                  explicitly; this is not a network-side default.
                required: true
                properties:
                  - name: type
                    type: string
                    enumValues:
                      - l2Snapshot
                    required: true
                  - name: symbol
                    type: string
                    description: Playground example prefill; not a network-side default.
                    required: true
                  - name: nlevels
                    type: number
                    description: Playground example prefill; not a network-side default.
                    required: false
                  - name: aggregation
                    type: number
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            method:
              type: string
              enum:
                - subscribe
              default: subscribe
              x-parser-schema-id: <anonymous-schema-97>
            subscription:
              type: array
              items:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - l2Snapshot
                    default: l2Snapshot
                    x-parser-schema-id: <anonymous-schema-100>
                  symbol:
                    type: string
                    default: BTC-USD
                    description: Playground example prefill; not a network-side default.
                    x-parser-schema-id: <anonymous-schema-101>
                  nlevels:
                    type: number
                    default: 10
                    description: Playground example prefill; not a network-side default.
                    x-parser-schema-id: <anonymous-schema-102>
                  aggregation:
                    type: number
                    x-parser-schema-id: <anonymous-schema-103>
                required:
                  - type
                  - symbol
                x-parser-schema-id: <anonymous-schema-99>
              minItems: 1
              default:
                - type: l2Snapshot
                  symbol: BTC-USD
                  nlevels: 10
              description: >-
                Playground example prefill. Send the subscription array
                explicitly; this is not a network-side default.
              x-parser-schema-id: <anonymous-schema-98>
          required:
            - method
            - subscription
          x-parser-schema-id: <anonymous-schema-96>
        title: L2 order book subscribe
        description: >-
          Schema defaults on this request are playground example prefills, not
          omitted-field defaults accepted by the network endpoint.
        example: |-
          {
            "method": "subscribe",
            "subscription": [
              {
                "type": "l2Snapshot",
                "symbol": "BTC-USD",
                "nlevels": 10,
                "aggregation": 0.5
              }
            ]
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribe
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: l2-orderbook
  - &ref_2
    id: l2-orderbookEvents
    title: L2 order book events
    type: send
    messages:
      - &ref_4
        id: l2Snapshot
        contentType: application/json
        payload:
          - name: L2 order book l2Snapshot
            description: Network-published l2Snapshot
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - l2Snapshot
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: book
                    type: object
                    required: false
                    properties:
                      - name: updateType
                        type: string
                        required: false
                      - name: symbol
                        type: string
                        required: false
                      - name: levels
                        type: array
                        description: >-
                          [bids, asks]. Delta sizes are absolute; zero deletes a
                          price level.
                        required: false
                        properties:
                          - name: item
                            type: array
                            required: false
                            properties:
                              - name: px
                                type: number
                                required: false
                              - name: sz
                                type: number
                                required: false
                              - name: 'n'
                                type: number
                                required: false
                      - name: timestamp
                        type: number
                        description: Unix timestamp in nanoseconds.
                        required: false
              - name: topic
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - l2Snapshot
              x-parser-schema-id: <anonymous-schema-105>
            data:
              type: object
              properties:
                book:
                  type: object
                  properties:
                    updateType:
                      type: string
                      x-parser-schema-id: <anonymous-schema-108>
                    symbol:
                      type: string
                      x-parser-schema-id: <anonymous-schema-109>
                    levels:
                      type: array
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            px:
                              type: number
                              x-parser-schema-id: <anonymous-schema-113>
                            sz:
                              type: number
                              x-parser-schema-id: <anonymous-schema-114>
                            'n':
                              type: number
                              x-parser-schema-id: <anonymous-schema-115>
                          x-parser-schema-id: <anonymous-schema-112>
                        x-parser-schema-id: <anonymous-schema-111>
                      minItems: 2
                      maxItems: 2
                      description: >-
                        [bids, asks]. Delta sizes are absolute; zero deletes a
                        price level.
                      x-parser-schema-id: <anonymous-schema-110>
                    timestamp:
                      type: number
                      description: Unix timestamp in nanoseconds.
                      x-parser-schema-id: <anonymous-schema-116>
                  x-parser-schema-id: <anonymous-schema-107>
              x-parser-schema-id: <anonymous-schema-106>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-117>
          required:
            - type
            - data
            - topic
          x-parser-schema-id: <anonymous-schema-104>
        title: L2 order book l2Snapshot
        description: Network-published l2Snapshot
        example: |-
          {
            "type": "l2Snapshot",
            "data": {
              "book": {
                "updateType": "snapshot",
                "symbol": "BTC-USD",
                "levels": [
                  [
                    {
                      "px": 102777,
                      "sz": 1.5,
                      "n": 3
                    },
                    {
                      "px": 102776.5,
                      "sz": 2.3,
                      "n": 5
                    },
                    {
                      "px": 102776,
                      "sz": 0.8,
                      "n": 2
                    }
                  ],
                  [
                    {
                      "px": 102780,
                      "sz": 2,
                      "n": 4
                    },
                    {
                      "px": 102780.5,
                      "sz": 1.2,
                      "n": 3
                    },
                    {
                      "px": 102781,
                      "sz": 1.8,
                      "n": 2
                    }
                  ]
                ],
                "timestamp": 1699564800000000000
              }
            },
            "topic": "l2snapshot.BTC-USD.10.0.5"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: l2Snapshot
      - &ref_5
        id: subscribed
        contentType: application/json
        payload:
          - name: L2 order book subscribed
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - subscriptionResponse
                required: true
              - name: topics
                type: array
                required: false
                properties:
                  - name: item
                    type: string
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - subscriptionResponse
              x-parser-schema-id: <anonymous-schema-119>
            topics:
              type: array
              items:
                type: string
                x-parser-schema-id: <anonymous-schema-121>
              x-parser-schema-id: <anonymous-schema-120>
          required:
            - type
          x-parser-schema-id: <anonymous-schema-118>
        title: L2 order book subscribed
        example: |-
          {
            "type": "subscriptionResponse",
            "topics": [
              "l2snapshot.BTC-USD.10.0.5"
            ]
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: subscribed
      - &ref_6
        id: unsubscribed
        contentType: application/json
        payload:
          - name: L2 order book unsubscribed
            type: object
            properties:
              - name: type
                type: string
                enumValues:
                  - unsubscribeResponse
                required: true
              - name: topic
                type: string
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            type:
              type: string
              enum:
                - unsubscribeResponse
              x-parser-schema-id: <anonymous-schema-123>
            topic:
              type: string
              x-parser-schema-id: <anonymous-schema-124>
          required:
            - type
          x-parser-schema-id: <anonymous-schema-122>
        title: L2 order book unsubscribed
        example: |-
          {
            "type": "unsubscribeResponse",
            "topic": "l2snapshot.BTC-USD.10.0.5"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: unsubscribed
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_1
receiveOperations:
  - *ref_2
sendMessages:
  - *ref_3
receiveMessages:
  - *ref_4
  - *ref_5
  - *ref_6
extensions:
  - id: x-parser-unique-object-id
    value: l2-orderbook
securitySchemes: []

````

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