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

# Subscribe: Spot Trades

> Subscribe to the `tradesSpot` channel.

Optional `markets` and `numPastTrades` (number of historical trades on subscribe).

Send this subscription over the shared /ws connection; /ws/tradesSpot is a documentation route, not a separate socket URL. See the [Spot API guide](/api-reference/spot-api-guide).



## OpenAPI

````yaml /api-reference/ws-spec.json post /ws/tradesSpot
openapi: 3.0.3
info:
  title: Ondo Perps WebSocket API
  version: '1.0'
  description: >-
    WebSocket API for Ondo Perps: real-time market data, order updates,
    positions, balance, funding, and more.


    ## Connection


    Connect via `wss://api.ondoperps.xyz/ws`. The server enforces a 32 KB max
    message size and a rate limit of 25 requests/second (burst 50).


    ## Authentication


    Public channels (market data) require no authentication. Private channels
    (orders, fills, positions, balance, etc.) require a `login` message first.


    ### JWT Login

    ```json

    {"op": "login", "args": {"token": "<JWT>"}}

    ```


    ### API Key Login

    ```json

    {"op": "login", "args": {"key": "<api_key_id>", "time": "<unix_ms>", "sign":
    "<hex_hmac>"}}

    ```


    Signature: `HMAC-SHA256(api_secret, time + "ondo_perps_ws_login" )`


    ## Heartbeat


    Send `{"op": "ping"}` periodically. The server responds with `{"type":
    "pong"}`. Connections idle for 180 seconds are closed.


    ## Message Format


    ### Client → Server

    All client messages use the `op` field: `ping`, `login`, `subscribe`,
    `unsubscribe`, `sendMessage`.


    ### Server → Client

    All server messages use the `type` field: `pong`, `loggedIn`, `subscribed`,
    `unsubscribed`, `update`, `error`.

    Channel data updates arrive as `{"type": "update", "channel": "<name>",
    "data": <payload>}`.
servers:
  - url: wss://api.ondoperps.xyz
    description: Production
security: []
paths:
  /ws/tradesSpot:
    post:
      tags:
        - Spot public channels
      summary: 'Subscribe: Spot Trades'
      description: >-
        Subscribe to the `tradesSpot` channel.


        Optional `markets` and `numPastTrades` (number of historical trades on
        subscribe).


        Send this subscription over the shared /ws connection; /ws/tradesSpot is
        a documentation route, not a separate socket URL. See the [Spot API
        guide](/api-reference/spot-api-guide).
      operationId: subscribe_tradesSpot
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - op
                - channel
              properties:
                op:
                  type: string
                  enum:
                    - subscribe
                    - unsubscribe
                  example: subscribe
                  description: Operation type.
                channel:
                  type: string
                  enum:
                    - tradesSpot
                  example: tradesSpot
                  description: Channel for this subscription.
                markets:
                  type: array
                  items:
                    type: string
                  example:
                    - NVDA-USDC
                  description: >-
                    Markets to filter by. Optional; if omitted, all available
                    markets are used.
                numPastTrades:
                  type: integer
                  example: 50
                  description: Number of historical trades to receive on subscribe.
            example:
              op: subscribe
              channel: tradesSpot
              markets:
                - NVDA-USDC
              numPastTrades: 50
      responses:
        '200':
          description: Channel update for `tradesSpot`
          content:
            application/json:
              schema:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - update
                  channel:
                    type: string
                    enum:
                      - tradesSpot
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/SpotTrade'
              example:
                type: update
                channel: tradesSpot
                data:
                  - market: SPY-USDC
                    price: '227.50'
                    size: '5.00'
                    cost: '1137.50'
                    aggressor_side: buy
                    time: '2025-03-05T14:30:00Z'
                    id: 70a37d8f972f2494837f9dba8364cbb4
components:
  schemas:
    SpotTrade:
      type: object
      required:
        - market
        - price
        - size
        - cost
        - aggressor_side
        - time
        - id
      properties:
        market:
          type: string
          description: Trading market
          example: SPY-USDC
        price:
          type: string
          description: Trade price
          example: '1.55'
        size:
          type: string
          description: Trade size in base currency
          example: '5.403'
        cost:
          type: string
          description: Trade cost in quote currency
          example: '8.37465'
        aggressor_side:
          type: string
          description: Side of the aggressing (taker) order
          enum:
            - buy
            - sell
          example: buy
        time:
          type: string
          format: date-time
          description: Time the trade occurred
          example: '2022-06-16T12:35:11.123456Z'
        id:
          type: string
          description: Trade/fill ID
          example: 70a37d8f972f2494837f9dba8364cbb4

````

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