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

# Public Trades Stream

> Real-time trade updates and snapshots for a specific market.

This stream is available on the `publicTrades` subscription. It provides real-time trade updates for a specified market via `publicCompletedOrdersDelta` push messages, plus on-demand snapshots of recent trades via `emitPublicCompletedOrders`.

#### Snapshot vs. Delta

The `emitPublicCompletedOrders` request returns a snapshot of recent trades via `publicCompletedOrders`. Use it for:

* Initial state hydration when first connecting to the stream
* Recovery after reconnects or connection interruptions
* Verifying historical execution completeness
* Getting recent trade history before processing real-time delta updates
* Reconciling local trade history with server state


## AsyncAPI

````yaml latest/perps/asyncapi/perps-ws.yaml publicTradesStream
id: publicTradesStream
title: Public Trades Stream
description: >
  Available on the `publicTrades` subscription. Real-time trade executions and
  on-demand snapshots for a specific market.
servers:
  - id: sandbox
    protocol: wss
    host: ws.sandbox.rails.xyz
    bindings: []
    variables: []
address: '?product=perpetuals&market={market}&subscriptions=publicTrades'
parameters:
  - id: market
    jsonSchema:
      type: string
      description: >
        A specific market (e.g. `BTC-USDT`) or `ALL`. When `ALL` is used,
        `market` must be supplied explicitly in the `content` of every request
        that accepts it.
      default: BTC-USDT
    description: >
      A specific market (e.g. `BTC-USDT`) or `ALL`. When `ALL` is used, `market`
      must be supplied explicitly in the `content` of every request that accepts
      it.
    type: string
    required: true
    deprecated: false
bindings: []
operations:
  - &ref_2
    id: emitPublicCompletedOrders
    title: Emit public completed orders
    description: >
      Request a snapshot of recent public trades. Useful for initial state
      hydration, reconnect recovery, and reconciliation before processing delta
      updates.
    type: receive
    messages:
      - &ref_5
        id: emitPublicCompletedOrdersRequest
        contentType: application/json
        payload:
          - name: Emit Public Completed Orders
            type: object
            properties:
              - name: message
                type: string
                description: Always `emitPublicCompletedOrders`.
                required: true
              - name: content
                type: object
                required: false
                properties:
                  - name: clientRequestId
                    type: string
                    description: Client-generated UUID for correlation
                    required: false
                  - name: market
                    type: string
                    description: >-
                      Market name, only required when connecting with
                      `market=ALL`
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            message:
              type: string
              description: Always `emitPublicCompletedOrders`.
              x-parser-schema-id: <anonymous-schema-233>
            content:
              type: object
              properties:
                clientRequestId:
                  type: string
                  description: Client-generated UUID for correlation
                  x-parser-schema-id: <anonymous-schema-235>
                market:
                  type: string
                  description: Market name, only required when connecting with `market=ALL`
                  x-parser-schema-id: <anonymous-schema-236>
              x-parser-schema-id: <anonymous-schema-234>
          required:
            - message
          x-parser-schema-id: <anonymous-schema-232>
        title: Emit Public Completed Orders
        example: |-
          {
            "message": "emitPublicCompletedOrders",
            "content": {
              "clientRequestId": "4cc68b60-ed2d-42aa-a21e-cb5486f8fd1a",
              "market": "ETH-USDT"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: emitPublicCompletedOrdersRequest
    bindings: []
    extensions: &ref_0
      - id: x-parser-unique-object-id
        value: publicTradesStream
  - &ref_3
    id: publicCompletedOrdersSnapshot
    title: Public completed orders snapshot
    description: Response to `emitPublicCompletedOrders`.
    type: send
    messages:
      - &ref_6
        id: publicCompletedOrdersResponse
        contentType: application/json
        payload:
          - name: Public Trades Snapshot
            description: Response to `emitPublicCompletedOrders`.
            type: object
            properties:
              - name: resultType
                type: string
                description: Always `publicCompletedOrders`.
                required: true
              - name: market
                type: string
                description: Market name
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: clientRequestId
                    type: string
                    description: Client-generated UUID for correlation
                    required: false
                  - name: orders
                    type: array
                    description: Snapshot of recent trade executions
                    required: true
                    properties:
                      - name: executionType
                        type: string
                        description: Execution role
                        enumValues:
                          - taker
                          - maker
                        required: true
                      - name: matchId
                        type: string
                        description: Unique identifier for the trade match
                        required: true
                      - name: orderType
                        type: string
                        description: Order side
                        enumValues:
                          - buy
                          - sell
                        required: true
                      - name: price
                        type: string
                        description: Execution price
                        required: true
                      - name: quantity
                        type: string
                        description: Execution quantity
                        required: true
                      - name: updatedAt
                        type: integer
                        description: Execution timestamp (milliseconds since epoch)
                        required: true
                  - name: statusCode
                    type: integer
                    description: Always `200`.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            resultType:
              type: string
              description: Always `publicCompletedOrders`.
              x-parser-schema-id: <anonymous-schema-238>
            market:
              type: string
              description: Market name
              x-parser-schema-id: <anonymous-schema-239>
            data:
              type: object
              properties:
                clientRequestId:
                  type: string
                  description: Client-generated UUID for correlation
                  x-parser-schema-id: <anonymous-schema-241>
                orders:
                  type: array
                  description: Snapshot of recent trade executions
                  items: &ref_1
                    type: object
                    properties:
                      executionType:
                        type: string
                        enum:
                          - taker
                          - maker
                        description: Execution role
                        x-parser-schema-id: <anonymous-schema-243>
                      matchId:
                        type: string
                        description: Unique identifier for the trade match
                        x-parser-schema-id: <anonymous-schema-244>
                      orderType:
                        type: string
                        enum:
                          - buy
                          - sell
                        description: Order side
                        x-parser-schema-id: <anonymous-schema-245>
                      price:
                        type: string
                        description: Execution price
                        x-parser-schema-id: <anonymous-schema-246>
                      quantity:
                        type: string
                        description: Execution quantity
                        x-parser-schema-id: <anonymous-schema-247>
                      updatedAt:
                        type: integer
                        description: Execution timestamp (milliseconds since epoch)
                        x-parser-schema-id: <anonymous-schema-248>
                    required:
                      - executionType
                      - matchId
                      - orderType
                      - price
                      - quantity
                      - updatedAt
                    x-parser-schema-id: PublicTradeExecution
                  x-parser-schema-id: <anonymous-schema-242>
                statusCode:
                  type: integer
                  description: Always `200`.
                  x-parser-schema-id: <anonymous-schema-249>
              required:
                - orders
                - statusCode
              x-parser-schema-id: <anonymous-schema-240>
          required:
            - resultType
            - market
            - data
          x-parser-schema-id: <anonymous-schema-237>
        title: Public Trades Snapshot
        description: Response to `emitPublicCompletedOrders`.
        example: |-
          {
            "resultType": "publicCompletedOrders",
            "market": "ETH-USDT",
            "data": {
              "clientRequestId": "4cc68b60-ed2d-42aa-a21e-cb5486f8fd1a",
              "orders": [
                {
                  "executionType": "taker",
                  "matchId": "d65966ab-109c-491f-bb55-a6ccd0453153",
                  "orderType": "buy",
                  "price": "3181.41",
                  "quantity": "0.01",
                  "updatedAt": 1767762904115
                },
                {
                  "executionType": "maker",
                  "matchId": "9eb783a6-7abc-4e94-9d9c-fd404e7580eb",
                  "orderType": "sell",
                  "price": "3181.42",
                  "quantity": "0.02",
                  "updatedAt": 1767762810250
                }
              ],
              "statusCode": 200
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: publicCompletedOrdersResponse
    bindings: []
    extensions: *ref_0
  - &ref_4
    id: publicTradesUpdate
    title: Public trades update
    description: Pushed whenever new trades are executed in the subscribed market.
    type: send
    messages:
      - &ref_7
        id: publicCompletedOrdersDelta
        contentType: application/json
        payload:
          - name: Public Trades Delta
            type: object
            properties:
              - name: resultType
                type: string
                description: Always `publicCompletedOrdersDelta`.
                required: true
              - name: market
                type: string
                description: Market name
                required: true
              - name: data
                type: object
                required: true
                properties:
                  - name: orders
                    type: array
                    description: New trade executions since last update
                    required: true
                    properties:
                      - name: executionType
                        type: string
                        description: Execution role
                        enumValues:
                          - taker
                          - maker
                        required: true
                      - name: matchId
                        type: string
                        description: Unique identifier for the trade match
                        required: true
                      - name: orderType
                        type: string
                        description: Order side
                        enumValues:
                          - buy
                          - sell
                        required: true
                      - name: price
                        type: string
                        description: Execution price
                        required: true
                      - name: quantity
                        type: string
                        description: Execution quantity
                        required: true
                      - name: updatedAt
                        type: integer
                        description: Execution timestamp (milliseconds since epoch)
                        required: true
                  - name: statusCode
                    type: integer
                    description: Always `200`.
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            resultType:
              type: string
              description: Always `publicCompletedOrdersDelta`.
              x-parser-schema-id: <anonymous-schema-251>
            market:
              type: string
              description: Market name
              x-parser-schema-id: <anonymous-schema-252>
            data:
              type: object
              properties:
                orders:
                  type: array
                  description: New trade executions since last update
                  items: *ref_1
                  x-parser-schema-id: <anonymous-schema-254>
                statusCode:
                  type: integer
                  description: Always `200`.
                  x-parser-schema-id: <anonymous-schema-255>
              required:
                - orders
                - statusCode
              x-parser-schema-id: <anonymous-schema-253>
          required:
            - resultType
            - market
            - data
          x-parser-schema-id: <anonymous-schema-250>
        title: Public Trades Delta
        example: |-
          {
            "resultType": "publicCompletedOrdersDelta",
            "market": "ETH-USDT",
            "data": {
              "orders": [
                {
                  "executionType": "taker",
                  "matchId": "9eb783a6-7abc-4e94-9d9c-fd404e7580eb",
                  "orderType": "buy",
                  "price": "3181.41",
                  "quantity": "0.01",
                  "updatedAt": 1767762810250
                },
                {
                  "executionType": "maker",
                  "matchId": "d65966ab-109c-491f-bb55-a6ccd0453153",
                  "orderType": "sell",
                  "price": "3181.42",
                  "quantity": "0.02",
                  "updatedAt": 1767762904115
                }
              ],
              "statusCode": 200
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: publicCompletedOrdersDelta
    bindings: []
    extensions: *ref_0
sendOperations:
  - *ref_2
receiveOperations:
  - *ref_3
  - *ref_4
sendMessages:
  - *ref_5
receiveMessages:
  - *ref_6
  - *ref_7
extensions:
  - id: x-parser-unique-object-id
    value: publicTradesStream
securitySchemes:
  - id: wsAuth
    name: Sec-WebSocket-Protocol
    type: httpApiKey
    description: |
      Supply as `authorization#<JWT>` during the WebSocket handshake.
    in: header
    extensions: []

````