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

# Trades Stream

> Public trade-tape stream — receive every print as it lands.

Public trade-tape stream — receive every print as it lands.


## AsyncAPI

````yaml openpx.asyncapi.yaml trades
id: trades
title: Trades Stream
description: Public trade-tape stream — receive every print as it lands.
servers:
  - id: inprocess
    protocol: ws
    host: openpx-engine
    bindings: []
    variables: []
address: /v1/trades
parameters: []
bindings: []
operations:
  - &ref_15
    id: trades_subscribe
    title: Subscribe
    description: Add to the active trades subscription set
    type: send
    messages:
      - &ref_23
        id: trades_subscribe
        contentType: application/json
        payload:
          - name: Subscribe
            description: Add to the active trades 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-66>
            outcome:
              type: *ref_0
              description: Optional outcome filter for binary markets.
              x-parser-schema-id: <anonymous-schema-67>
          x-parser-schema-id: <anonymous-schema-65>
        title: Subscribe
        description: Add to the active trades subscription set
        example: |-
          {
            "market_id": "example",
            "outcome": "example"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: trades_subscribe
    bindings: []
    extensions: &ref_2
      - id: x-parser-unique-object-id
        value: trades
  - &ref_16
    id: trades_unsubscribe
    title: Unsubscribe
    description: Remove from the active trades subscription set
    type: send
    messages:
      - &ref_24
        id: trades_unsubscribe
        contentType: application/json
        payload:
          - name: Unsubscribe
            description: Remove from the active trades 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-69>
            outcome:
              type: *ref_1
              description: Optional outcome filter for binary markets.
              x-parser-schema-id: <anonymous-schema-70>
          x-parser-schema-id: <anonymous-schema-68>
        title: Unsubscribe
        description: Remove from the active trades subscription set
        example: |-
          {
            "market_id": "example",
            "outcome": "example"
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: trades_unsubscribe
    bindings: []
    extensions: *ref_2
  - &ref_9
    id: trades_receive_Trade
    title: Trade
    description: A public trade (any counterparty), not tied to a local order.
    type: receive
    messages:
      - &ref_17
        id: Trade
        contentType: application/json
        payload:
          - name: Trade
            description: A public trade (any counterparty), not tied to a local order.
            type: object
            properties:
              - name: kind
                type: string
                enumValues:
                  - Trade
                required: true
              - name: local_ts_ms
                type: integer
                required: true
              - name: trade
                type: object
                title: ActivityTrade
                description: >-
                  Activity events still carried inside `WsUpdate::Trade` /
                  `WsUpdate::Fill`. Retained as a typed payload alongside the
                  stream rather than as a separate per-token surface.


                  `exchange_ts_ms` is exchange-authoritative millis since epoch
                  — uniform with `WsUpdate::{Snapshot, Delta}::exchange_ts`, so
                  every timestamp on the WS surface is the same type (`u64`
                  millis). `chrono::DateTime` was more expressive but cost a
                  representation mismatch at every FFI boundary.
                required: true
                properties:
                  - name: aggressor_side
                    type: &ref_3
                      - string
                      - 'null'
                    required: false
                  - name: asset_id
                    type: string
                    required: true
                  - name: exchange_ts_ms
                    type: &ref_4
                      - integer
                      - 'null'
                    description: Exchange-authoritative timestamp (millis since epoch).
                    required: false
                  - name: fee_rate_bps
                    type: &ref_5
                      - integer
                      - 'null'
                    description: >-
                      Fee rate in basis points (e.g. 0 = no fee, 200 = 2%).
                      Polymarket `last_trade_price` events populate this.
                    required: false
                  - name: market_id
                    type: string
                    required: true
                  - name: outcome
                    type: &ref_6
                      - string
                      - 'null'
                    required: false
                  - name: price
                    type: number
                    required: true
                  - name: side
                    type: &ref_7
                      - string
                      - 'null'
                    required: false
                  - name: size
                    type: number
                    required: true
                  - name: source_channel
                    type: string
                    required: true
                  - name: trade_id
                    type: &ref_8
                      - string
                      - 'null'
                    required: false
        headers: []
        jsonPayloadSchema:
          description: A public trade (any counterparty), not tied to a local order.
          properties:
            kind:
              enum:
                - Trade
              type: string
              x-parser-schema-id: <anonymous-schema-52>
            local_ts_ms:
              format: uint64
              minimum: 0
              type: integer
              x-parser-schema-id: <anonymous-schema-53>
            trade:
              description: >-
                Activity events still carried inside `WsUpdate::Trade` /
                `WsUpdate::Fill`. Retained as a typed payload alongside the
                stream rather than as a separate per-token surface.


                `exchange_ts_ms` is exchange-authoritative millis since epoch —
                uniform with `WsUpdate::{Snapshot, Delta}::exchange_ts`, so
                every timestamp on the WS surface is the same type (`u64`
                millis). `chrono::DateTime` was more expressive but cost a
                representation mismatch at every FFI boundary.
              properties:
                aggressor_side:
                  type: *ref_3
                  x-parser-schema-id: <anonymous-schema-54>
                asset_id:
                  type: string
                  x-parser-schema-id: <anonymous-schema-55>
                exchange_ts_ms:
                  description: Exchange-authoritative timestamp (millis since epoch).
                  format: uint64
                  minimum: 0
                  type: *ref_4
                  x-parser-schema-id: <anonymous-schema-56>
                fee_rate_bps:
                  description: >-
                    Fee rate in basis points (e.g. 0 = no fee, 200 = 2%).
                    Polymarket `last_trade_price` events populate this.
                  format: uint32
                  minimum: 0
                  type: *ref_5
                  x-parser-schema-id: <anonymous-schema-57>
                market_id:
                  type: string
                  x-parser-schema-id: <anonymous-schema-58>
                outcome:
                  type: *ref_6
                  x-parser-schema-id: <anonymous-schema-59>
                price:
                  format: double
                  type: number
                  x-parser-schema-id: <anonymous-schema-60>
                side:
                  type: *ref_7
                  x-parser-schema-id: <anonymous-schema-61>
                size:
                  format: double
                  type: number
                  x-parser-schema-id: <anonymous-schema-62>
                source_channel:
                  type: string
                  x-parser-schema-id: <anonymous-schema-63>
                trade_id:
                  type: *ref_8
                  x-parser-schema-id: <anonymous-schema-64>
              required:
                - asset_id
                - market_id
                - price
                - size
                - source_channel
              title: ActivityTrade
              type: object
              x-parser-schema-id: ActivityTrade
          required:
            - kind
            - local_ts_ms
            - trade
          type: object
          x-parser-schema-id: Trade
        title: Trade
        description: A public trade (any counterparty), not tied to a local order.
        example: |-
          {
            "kind": "Trade",
            "local_ts_ms": 0,
            "trade": {
              "aggressor_side": "example",
              "asset_id": "example",
              "exchange_ts_ms": 0,
              "fee_rate_bps": 0,
              "market_id": "example",
              "outcome": "example",
              "price": 0.5,
              "side": "example",
              "size": 0.5,
              "source_channel": "example",
              "trade_id": "example"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: Trade
    bindings: []
    extensions: *ref_2
  - &ref_10
    id: trades_receive_Connected
    title: Connected
    description: Initial socket establishment.
    type: receive
    messages:
      - &ref_18
        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_11
    id: trades_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_19
        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_12
    id: trades_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_20
        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_13
    id: trades_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_21
        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:
              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
          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_14
    id: trades_receive_Error
    title: Error
    description: A non-fatal error observed on the connection (session continues).
    type: receive
    messages:
      - &ref_22
        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_9
  - *ref_10
  - *ref_11
  - *ref_12
  - *ref_13
  - *ref_14
receiveOperations:
  - *ref_15
  - *ref_16
sendMessages:
  - *ref_17
  - *ref_18
  - *ref_19
  - *ref_20
  - *ref_21
  - *ref_22
receiveMessages:
  - *ref_23
  - *ref_24
extensions:
  - id: x-parser-unique-object-id
    value: trades
securitySchemes: []

````