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

# Orderbook Stream

> Per-market L2 orderbook stream — `Snapshot` on subscribe, then `Delta` updates.

Per-market L2 orderbook stream — `Snapshot` on subscribe, then `Delta` updates.


## AsyncAPI

````yaml openpx.asyncapi.yaml orderbook
id: orderbook
title: Orderbook Stream
description: >-
  Per-market L2 orderbook stream — `Snapshot` on subscribe, then `Delta`
  updates.
servers:
  - id: inprocess
    protocol: ws
    host: openpx-engine
    bindings: []
    variables: []
address: /v1/orderbook
parameters: []
bindings: []
operations:
  - &ref_19
    id: orderbook_subscribe
    title: Subscribe
    description: Add to the active orderbook subscription set
    type: send
    messages:
      - &ref_29
        id: orderbook_subscribe
        contentType: application/json
        payload:
          - name: Subscribe
            description: Add to the active orderbook subscription set
            type: object
            properties:
              - name: market_id
                type: string
                description: >-
                  Native market identifier (Kalshi ticker or Polymarket
                  condition_id).
                required: true
              - name: outcome
                type: &ref_0
                  - string
                  - 'null'
                description: Optional outcome filter for binary markets.
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - market_id
          properties:
            market_id:
              type: string
              description: >-
                Native market identifier (Kalshi ticker or Polymarket
                condition_id).
              x-parser-schema-id: <anonymous-schema-47>
            outcome:
              type: *ref_0
              description: Optional outcome filter for binary markets.
              x-parser-schema-id: <anonymous-schema-48>
          x-parser-schema-id: <anonymous-schema-46>
        title: Subscribe
        description: Add to the active orderbook subscription set
        example: |-
          {
            "market_id": "example",
            "outcome": "example"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: orderbook_subscribe
    bindings: []
    extensions: &ref_2
      - id: x-parser-unique-object-id
        value: orderbook
  - &ref_20
    id: orderbook_unsubscribe
    title: Unsubscribe
    description: Remove from the active orderbook subscription set
    type: send
    messages:
      - &ref_30
        id: orderbook_unsubscribe
        contentType: application/json
        payload:
          - name: Unsubscribe
            description: Remove from the active orderbook subscription set
            type: object
            properties:
              - name: market_id
                type: string
                description: >-
                  Native market identifier (Kalshi ticker or Polymarket
                  condition_id).
                required: true
              - name: outcome
                type: &ref_1
                  - string
                  - 'null'
                description: Optional outcome filter for binary markets.
                required: false
        headers: []
        jsonPayloadSchema:
          type: object
          required:
            - market_id
          properties:
            market_id:
              type: string
              description: >-
                Native market identifier (Kalshi ticker or Polymarket
                condition_id).
              x-parser-schema-id: <anonymous-schema-50>
            outcome:
              type: *ref_1
              description: Optional outcome filter for binary markets.
              x-parser-schema-id: <anonymous-schema-51>
          x-parser-schema-id: <anonymous-schema-49>
        title: Unsubscribe
        description: Remove from the active orderbook subscription set
        example: |-
          {
            "market_id": "example",
            "outcome": "example"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: orderbook_unsubscribe
    bindings: []
    extensions: *ref_2
  - &ref_11
    id: orderbook_receive_Snapshot
    title: Snapshot
    description: >-
      Full orderbook snapshot — replace any cached book for `(market_id,
      asset_id)`.
    type: receive
    messages:
      - &ref_21
        id: Snapshot
        contentType: application/json
        payload:
          - name: Snapshot
            description: >-
              Full orderbook snapshot — replace any cached book for `(market_id,
              asset_id)`.
            type: object
            properties:
              - name: asset_id
                type: string
                required: true
              - name: book
                type: object
                description: Full-depth L2 orderbook for one asset.
                required: true
                properties:
                  - name: asks
                    type: array
                    description: Ask levels, sorted ascending by price.
                    required: true
                    properties:
                      - name: price
                        type: number
                        description: Price as YES probability in `[0, 1]` (e.g. `0.62`).
                        required: true
                      - name: size
                        type: number
                        description: >-
                          Resting size at this price in contracts (e.g.
                          `100.0`).
                        required: true
                  - name: asset_id
                    type: string
                    description: >-
                      The orderable asset — Kalshi market ticker or Polymarket
                      CTF token id (e.g. `"KXBTCD-25APR1517"`).
                    required: true
                  - name: bids
                    type: array
                    description: Bid levels, sorted descending by price.
                    required: true
                    properties:
                      - name: price
                        type: number
                        description: Price as YES probability in `[0, 1]` (e.g. `0.62`).
                        required: true
                      - name: size
                        type: number
                        description: >-
                          Resting size at this price in contracts (e.g.
                          `100.0`).
                        required: true
                  - name: hash
                    type: &ref_4
                      - string
                      - 'null'
                    description: >-
                      Polymarket book-state hash for replay integrity; `null` on
                      Kalshi.
                    required: false
                  - name: last_update_id
                    type: &ref_5
                      - integer
                      - 'null'
                    description: >-
                      Monotonic sequence id from upstream; `null` when not
                      provided.
                    required: false
                  - name: timestamp
                    type: &ref_6
                      - string
                      - 'null'
                    description: >-
                      Upstream snapshot time in UTC (e.g.
                      `"2026-04-25T12:00:00Z"`).
                    required: false
              - name: exchange_ts
                type: &ref_7
                  - integer
                  - 'null'
                required: false
              - name: kind
                type: string
                enumValues:
                  - Snapshot
                required: true
              - name: local_ts_ms
                type: integer
                required: true
              - name: market_id
                type: string
                required: true
              - name: seq
                type: integer
                required: true
        headers: []
        jsonPayloadSchema:
          description: >-
            Full orderbook snapshot — replace any cached book for `(market_id,
            asset_id)`.
          properties:
            asset_id:
              type: string
              x-parser-schema-id: <anonymous-schema-1>
            book:
              description: Full-depth L2 orderbook for one asset.
              properties:
                asks:
                  description: Ask levels, sorted ascending by price.
                  items: &ref_3
                    description: A single resting orderbook level.
                    properties:
                      price:
                        allOf:
                          - &ref_8
                            format: double
                            type: number
                            x-parser-schema-id: number
                        description: Price as YES probability in `[0, 1]` (e.g. `0.62`).
                        x-parser-schema-id: <anonymous-schema-3>
                      size:
                        description: >-
                          Resting size at this price in contracts (e.g.
                          `100.0`).
                        format: double
                        type: number
                        x-parser-schema-id: <anonymous-schema-4>
                    required:
                      - price
                      - size
                    type: object
                    x-parser-schema-id: PriceLevel
                  type: array
                  x-parser-schema-id: <anonymous-schema-2>
                asset_id:
                  description: >-
                    The orderable asset — Kalshi market ticker or Polymarket CTF
                    token id (e.g. `"KXBTCD-25APR1517"`).
                  type: string
                  x-parser-schema-id: <anonymous-schema-5>
                bids:
                  description: Bid levels, sorted descending by price.
                  items: *ref_3
                  type: array
                  x-parser-schema-id: <anonymous-schema-6>
                hash:
                  description: >-
                    Polymarket book-state hash for replay integrity; `null` on
                    Kalshi.
                  type: *ref_4
                  x-parser-schema-id: <anonymous-schema-7>
                last_update_id:
                  description: >-
                    Monotonic sequence id from upstream; `null` when not
                    provided.
                  format: uint64
                  minimum: 0
                  type: *ref_5
                  x-parser-schema-id: <anonymous-schema-8>
                timestamp:
                  description: >-
                    Upstream snapshot time in UTC (e.g.
                    `"2026-04-25T12:00:00Z"`).
                  format: date-time
                  type: *ref_6
                  x-parser-schema-id: <anonymous-schema-9>
              required:
                - asks
                - asset_id
                - bids
              type: object
              x-parser-schema-id: Orderbook
            exchange_ts:
              format: uint64
              minimum: 0
              type: *ref_7
              x-parser-schema-id: <anonymous-schema-10>
            kind:
              enum:
                - Snapshot
              type: string
              x-parser-schema-id: <anonymous-schema-11>
            local_ts_ms:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-12>
            market_id:
              type: string
              x-parser-schema-id: <anonymous-schema-13>
            seq:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-14>
          required:
            - asset_id
            - book
            - kind
            - local_ts_ms
            - market_id
            - seq
          type: object
          x-parser-schema-id: Snapshot
        title: Snapshot
        description: >-
          Full orderbook snapshot — replace any cached book for `(market_id,
          asset_id)`.
        example: |-
          {
            "asset_id": "example",
            "book": {
              "asks": [
                null
              ],
              "asset_id": "example",
              "bids": [
                null
              ],
              "hash": "example",
              "last_update_id": 0,
              "timestamp": "2026-01-01T00:00:00Z"
            },
            "exchange_ts": 0,
            "kind": "Snapshot",
            "local_ts_ms": 0,
            "market_id": "example",
            "seq": 0
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Snapshot
    bindings: []
    extensions: *ref_2
  - &ref_12
    id: orderbook_receive_Delta
    title: Delta
    description: Incremental change to an existing book — apply in-place.
    type: receive
    messages:
      - &ref_22
        id: Delta
        contentType: application/json
        payload:
          - name: Delta
            description: Incremental change to an existing book — apply in-place.
            type: object
            properties:
              - name: asset_id
                type: string
                required: true
              - name: changes
                type: array
                required: true
                properties:
                  - name: price
                    type: number
                    description: Price as YES probability in `[0, 1]` (e.g. `0.62`).
                    required: true
                  - name: side
                    type: string
                    description: 'Which side. Options: `bid`, `ask`.'
                    required: true
                  - name: size
                    type: number
                    description: >-
                      New size at this price in contracts; `0` removes the
                      level.
                    required: true
              - name: exchange_ts
                type: &ref_9
                  - integer
                  - 'null'
                required: false
              - name: kind
                type: string
                enumValues:
                  - Delta
                required: true
              - name: local_ts_ms
                type: integer
                required: true
              - name: market_id
                type: string
                required: true
              - name: seq
                type: integer
                required: true
        headers: []
        jsonPayloadSchema:
          description: Incremental change to an existing book — apply in-place.
          properties:
            asset_id:
              type: string
              x-parser-schema-id: <anonymous-schema-15>
            changes:
              items:
                description: >-
                  One price-level update; `size > 0` sets the level, `size == 0`
                  removes it.
                properties:
                  price:
                    allOf:
                      - *ref_8
                    description: Price as YES probability in `[0, 1]` (e.g. `0.62`).
                    x-parser-schema-id: <anonymous-schema-17>
                  side:
                    allOf:
                      - description: 'Side of an orderbook level. Options: `bid`, `ask`.'
                        enum:
                          - bid
                          - ask
                        type: string
                        x-parser-schema-id: PriceLevelSide
                    description: 'Which side. Options: `bid`, `ask`.'
                    x-parser-schema-id: <anonymous-schema-18>
                  size:
                    description: >-
                      New size at this price in contracts; `0` removes the
                      level.
                    format: double
                    type: number
                    x-parser-schema-id: <anonymous-schema-19>
                required:
                  - price
                  - side
                  - size
                type: object
                x-parser-schema-id: PriceLevelChange
              type: array
              x-parser-schema-id: <anonymous-schema-16>
            exchange_ts:
              format: uint64
              minimum: 0
              type: *ref_9
              x-parser-schema-id: <anonymous-schema-20>
            kind:
              enum:
                - Delta
              type: string
              x-parser-schema-id: <anonymous-schema-21>
            local_ts_ms:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-22>
            market_id:
              type: string
              x-parser-schema-id: <anonymous-schema-23>
            seq:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-24>
          required:
            - asset_id
            - changes
            - kind
            - local_ts_ms
            - market_id
            - seq
          type: object
          x-parser-schema-id: Delta
        title: Delta
        description: Incremental change to an existing book — apply in-place.
        example: |-
          {
            "asset_id": "example",
            "changes": [
              {
                "price": null,
                "side": null,
                "size": 0.5
              }
            ],
            "exchange_ts": 0,
            "kind": "Delta",
            "local_ts_ms": 0,
            "market_id": "example",
            "seq": 0
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Delta
    bindings: []
    extensions: *ref_2
  - &ref_13
    id: orderbook_receive_Clear
    title: Clear
    description: Book invalidation — drop the cached book and wait for the next `Snapshot`.
    type: receive
    messages:
      - &ref_23
        id: Clear
        contentType: application/json
        payload:
          - name: Clear
            description: >-
              Book invalidation — drop the cached book and wait for the next
              `Snapshot`.
            type: object
            properties:
              - name: asset_id
                type: string
                required: true
              - name: kind
                type: string
                enumValues:
                  - Clear
                required: true
              - name: local_ts_ms
                type: integer
                required: true
              - name: market_id
                type: string
                required: true
              - name: reason
                type: oneOf
                description: >-
                  Why a specific book was invalidated — handed to users so they
                  can decide whether to alert, log, or handle it silently.
                required: true
                properties:
                  - name: SequenceGap
                    type: object
                    required: true
                    properties:
                      - name: expected
                        type: integer
                        required: true
                      - name: received
                        type: integer
                        required: true
              - name: seq
                type: integer
                required: true
        headers: []
        jsonPayloadSchema:
          description: >-
            Book invalidation — drop the cached book and wait for the next
            `Snapshot`.
          properties:
            asset_id:
              type: string
              x-parser-schema-id: <anonymous-schema-25>
            kind:
              enum:
                - Clear
              type: string
              x-parser-schema-id: <anonymous-schema-26>
            local_ts_ms:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-27>
            market_id:
              type: string
              x-parser-schema-id: <anonymous-schema-28>
            reason: &ref_10
              description: >-
                Why a specific book was invalidated — handed to users so they
                can decide whether to alert, log, or handle it silently.
              oneOf:
                - enum:
                    - Reconnect
                    - Lag
                    - ExchangeReset
                  type: string
                  x-parser-schema-id: <anonymous-schema-29>
                - additionalProperties: false
                  properties:
                    SequenceGap:
                      properties:
                        expected:
                          format: uint64
                          minimum: 0
                          type: integer
                          x-parser-schema-id: <anonymous-schema-32>
                        received:
                          format: uint64
                          minimum: 0
                          type: integer
                          x-parser-schema-id: <anonymous-schema-33>
                      required:
                        - expected
                        - received
                      type: object
                      x-parser-schema-id: <anonymous-schema-31>
                  required:
                    - SequenceGap
                  type: object
                  x-parser-schema-id: <anonymous-schema-30>
              x-parser-schema-id: InvalidationReason
            seq:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-34>
          required:
            - asset_id
            - kind
            - local_ts_ms
            - market_id
            - reason
            - seq
          type: object
          x-parser-schema-id: Clear
        title: Clear
        description: >-
          Book invalidation — drop the cached book and wait for the next
          `Snapshot`.
        example: |-
          {
            "asset_id": "example",
            "kind": "Clear",
            "local_ts_ms": 0,
            "market_id": "example",
            "reason": null,
            "seq": 0
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Clear
    bindings: []
    extensions: *ref_2
  - &ref_14
    id: orderbook_receive_Connected
    title: Connected
    description: Initial socket establishment.
    type: receive
    messages:
      - &ref_24
        id: Connected
        contentType: application/json
        payload:
          - name: Connected
            description: Initial socket establishment.
            type: object
            properties:
              - name: kind
                type: string
                enumValues:
                  - Connected
                required: true
        headers: []
        jsonPayloadSchema:
          description: Initial socket establishment.
          properties:
            kind:
              enum:
                - Connected
              type: string
              x-parser-schema-id: <anonymous-schema-35>
          required:
            - kind
          type: object
          x-parser-schema-id: Connected
        title: Connected
        description: Initial socket establishment.
        example: |-
          {
            "kind": "Connected"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Connected
    bindings: []
    extensions: *ref_2
  - &ref_15
    id: orderbook_receive_Reconnected
    title: Reconnected
    description: >-
      Socket re-established after an outage — `gap_ms` is the wall-clock
      interval since the last received message.
    type: receive
    messages:
      - &ref_25
        id: Reconnected
        contentType: application/json
        payload:
          - name: Reconnected
            description: >-
              Socket re-established after an outage — `gap_ms` is the wall-clock
              interval since the last received message.
            type: object
            properties:
              - name: gap_ms
                type: integer
                required: true
              - name: kind
                type: string
                enumValues:
                  - Reconnected
                required: true
        headers: []
        jsonPayloadSchema:
          description: >-
            Socket re-established after an outage — `gap_ms` is the wall-clock
            interval since the last received message.
          properties:
            gap_ms:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-36>
            kind:
              enum:
                - Reconnected
              type: string
              x-parser-schema-id: <anonymous-schema-37>
          required:
            - gap_ms
            - kind
          type: object
          x-parser-schema-id: Reconnected
        title: Reconnected
        description: >-
          Socket re-established after an outage — `gap_ms` is the wall-clock
          interval since the last received message.
        example: |-
          {
            "gap_ms": 0,
            "kind": "Reconnected"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Reconnected
    bindings: []
    extensions: *ref_2
  - &ref_16
    id: orderbook_receive_Lagged
    title: Lagged
    description: >-
      Slow consumer dropped messages — every affected book is invalidated and
      must be rebuilt from the next `Snapshot`.
    type: receive
    messages:
      - &ref_26
        id: Lagged
        contentType: application/json
        payload:
          - name: Lagged
            description: >-
              Slow consumer dropped messages — every affected book is
              invalidated and must be rebuilt from the next `Snapshot`.
            type: object
            properties:
              - name: dropped
                type: integer
                required: true
              - name: first_seq
                type: integer
                required: true
              - name: kind
                type: string
                enumValues:
                  - Lagged
                required: true
              - name: last_seq
                type: integer
                required: true
        headers: []
        jsonPayloadSchema:
          description: >-
            Slow consumer dropped messages — every affected book is invalidated
            and must be rebuilt from the next `Snapshot`.
          properties:
            dropped:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-38>
            first_seq:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-39>
            kind:
              enum:
                - Lagged
              type: string
              x-parser-schema-id: <anonymous-schema-40>
            last_seq:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-41>
          required:
            - dropped
            - first_seq
            - kind
            - last_seq
          type: object
          x-parser-schema-id: Lagged
        title: Lagged
        description: >-
          Slow consumer dropped messages — every affected book is invalidated
          and must be rebuilt from the next `Snapshot`.
        example: |-
          {
            "dropped": 0,
            "first_seq": 0,
            "kind": "Lagged",
            "last_seq": 0
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Lagged
    bindings: []
    extensions: *ref_2
  - &ref_17
    id: orderbook_receive_BookInvalidated
    title: BookInvalidated
    description: >-
      A specific market's book is no longer trustworthy — drop cache and wait
      for next `Snapshot` (reasons: `Reconnect`, `Lag`, `SequenceGap`,
      `ExchangeReset`).
    type: receive
    messages:
      - &ref_27
        id: BookInvalidated
        contentType: application/json
        payload:
          - name: BookInvalidated
            description: >-
              A specific market's book is no longer trustworthy — drop cache and
              wait for next `Snapshot` (reasons: `Reconnect`, `Lag`,
              `SequenceGap`, `ExchangeReset`).
            type: object
            properties:
              - name: kind
                type: string
                enumValues:
                  - BookInvalidated
                required: true
              - name: market_id
                type: string
                required: true
              - name: reason
                type: oneOf
                description: >-
                  Why a specific book was invalidated — handed to users so they
                  can decide whether to alert, log, or handle it silently.
                required: true
                properties:
                  - name: SequenceGap
                    type: object
                    required: true
                    properties:
                      - name: expected
                        type: integer
                        required: true
                      - name: received
                        type: integer
                        required: true
        headers: []
        jsonPayloadSchema:
          description: >-
            A specific market's book is no longer trustworthy — drop cache and
            wait for next `Snapshot` (reasons: `Reconnect`, `Lag`,
            `SequenceGap`, `ExchangeReset`).
          properties:
            kind:
              enum:
                - BookInvalidated
              type: string
              x-parser-schema-id: <anonymous-schema-42>
            market_id:
              type: string
              x-parser-schema-id: <anonymous-schema-43>
            reason: *ref_10
          required:
            - kind
            - market_id
            - reason
          type: object
          x-parser-schema-id: BookInvalidated
        title: Book invalidated
        description: >-
          A specific market's book is no longer trustworthy — drop cache and
          wait for next `Snapshot` (reasons: `Reconnect`, `Lag`, `SequenceGap`,
          `ExchangeReset`).
        example: |-
          {
            "kind": "BookInvalidated",
            "market_id": "example",
            "reason": null
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: BookInvalidated
    bindings: []
    extensions: *ref_2
  - &ref_18
    id: orderbook_receive_Error
    title: Error
    description: A non-fatal error observed on the connection (session continues).
    type: receive
    messages:
      - &ref_28
        id: Error
        contentType: application/json
        payload:
          - name: Error
            description: A non-fatal error observed on the connection (session continues).
            type: object
            properties:
              - name: kind
                type: string
                enumValues:
                  - Error
                required: true
              - name: message
                type: string
                required: true
        headers: []
        jsonPayloadSchema:
          description: A non-fatal error observed on the connection (session continues).
          properties:
            kind:
              enum:
                - Error
              type: string
              x-parser-schema-id: <anonymous-schema-44>
            message:
              type: string
              x-parser-schema-id: <anonymous-schema-45>
          required:
            - kind
            - message
          type: object
          x-parser-schema-id: Error
        title: Error
        description: A non-fatal error observed on the connection (session continues).
        example: |-
          {
            "kind": "Error",
            "message": "example"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Error
    bindings: []
    extensions: *ref_2
sendOperations:
  - *ref_11
  - *ref_12
  - *ref_13
  - *ref_14
  - *ref_15
  - *ref_16
  - *ref_17
  - *ref_18
receiveOperations:
  - *ref_19
  - *ref_20
sendMessages:
  - *ref_21
  - *ref_22
  - *ref_23
  - *ref_24
  - *ref_25
  - *ref_26
  - *ref_27
  - *ref_28
receiveMessages:
  - *ref_29
  - *ref_30
extensions:
  - id: x-parser-unique-object-id
    value: orderbook
securitySchemes: []

````