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

# trades

Subscribe to real-time trade executions with price, size, and side information for trading instruments.

## Example Request

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "trades",
    "symbol": "BTC-PERP"
  }
}
```

## Example Response

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "channel": "trades:BTC-PERP",
    "data": {
      "instrument_id": 1,
      "instrument": "BTC-PERP",
      "trade_id": 1977789105883768779,
      "tx_hash": "0x7f3f0051f155a58a9362882ec3fe01162d0c2c3123d32fc87f89ac31ab039c4d",
      "side": "b",
      "price": "67804",
      "size": "0.00303",
      "maker": "0x14191D72B99Fb42E712360eF518e983e87d551Ec",
      "taker": "0xeE1c303b69Fe40B74BB7c2408e99C5415928EFcb",
      "timestamp": 1770859894258
    }
  }
}
```

## WebSocket Client Examples

### Python

```python theme={null}
import websocket
import json

def on_message(ws, message):
    print(f"Received: {message}")

def on_open(ws):
    subscribe_msg = {
        "jsonrpc": "2.0",
        "id": "1",
        "method": "subscribe",
        "params": {
            "channel": "trades",
            "symbol": "BTC-PERP"
        }
    }
    ws.send(json.dumps(subscribe_msg))

ws = websocket.WebSocketApp("wss://api.hotstuff.trade/ws",
                          on_message=on_message,
                          on_open=on_open)
ws.run_forever()
```

### JavaScript

```javascript theme={null}
const ws = new WebSocket("wss://api.hotstuff.trade/ws");

ws.onopen = function () {
  const subscribeMsg = {
    jsonrpc: "2.0",
    id: "1",
    method: "subscribe",
    params: {
      channel: "trades",
      symbol: "BTC-PERP",
    },
  };
  ws.send(JSON.stringify(subscribeMsg));
};

ws.onmessage = function (event) {
  console.log("Received:", event.data);
};
```


## AsyncAPI

````yaml asyncapi/ws-subscriptions.json trades
id: trades
title: Trades
description: ''
servers:
  - id: production
    protocol: wss
    host: api.hotstuff.trade/ws
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_8
    id: trades_sendSubscribe
    title: Trades_send subscribe
    type: receive
    messages:
      - &ref_10
        id: a_subscribeRequest
        contentType: application/json
        payload:
          - name: Subscription request
            description: Send subscribe/unsubscribe request
            type: object
            properties:
              - name: jsonrpc
                type: string
                description: JSON-RPC version
                examples: &ref_0
                  - '2.0'
                required: true
              - name: id
                type: integer
                description: Client request identifier
                examples: &ref_1
                  - 1
                required: true
              - name: method
                type: string
                description: Subscription action
                enumValues:
                  - subscribe
                  - unsubscribe
                examples: &ref_2
                  - subscribe
                required: true
              - name: params
                type: object
                description: Channel subscription parameters
                required: true
                properties:
                  - name: channel
                    type: string
                    description: Must be `trades`
                    examples: &ref_3
                      - trades
                    required: true
                  - name: symbol
                    type: string
                    description: 'Example: BTC-PERP'
                    examples: &ref_4
                      - BTC-PERP
                    required: true
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              default: '2.0'
              examples: *ref_0
              description: JSON-RPC version
              x-parser-schema-id: <anonymous-schema-306>
            id:
              type: integer
              default: 1
              examples: *ref_1
              description: Client request identifier
              x-parser-schema-id: <anonymous-schema-307>
            method:
              type: string
              enum:
                - subscribe
                - unsubscribe
              default: subscribe
              examples: *ref_2
              description: Subscription action
              x-parser-schema-id: <anonymous-schema-308>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: Must be `trades`
                  default: trades
                  examples: *ref_3
                  x-parser-schema-id: <anonymous-schema-310>
                symbol:
                  type: string
                  description: 'Example: BTC-PERP'
                  default: BTC-PERP
                  examples: *ref_4
                  x-parser-schema-id: <anonymous-schema-311>
              required:
                - channel
                - symbol
              description: Channel subscription parameters
              x-parser-schema-id: <anonymous-schema-309>
          required:
            - jsonrpc
            - id
            - method
            - params
          x-parser-schema-id: <anonymous-schema-305>
        title: Subscription request
        description: Send subscribe/unsubscribe request
        example: |-
          {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "subscribe",
            "params": {
              "channel": "trades",
              "symbol": "BTC-PERP"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: a_subscribeRequest
    bindings: []
    extensions: &ref_7
      - id: x-parser-unique-object-id
        value: trades
  - &ref_9
    id: trades_receiveEvent
    title: Trades_receive event
    type: send
    messages:
      - &ref_11
        id: event
        contentType: application/json
        payload:
          - name: Channel event
            description: Server-pushed JSON-RPC event
            type: object
            properties:
              - name: jsonrpc
                type: string
                required: false
              - name: method
                type: string
                required: false
              - name: params
                type: object
                required: false
                properties:
                  - name: channel
                    type: string
                    required: false
                  - name: data
                    type: object
                    required: false
                    properties:
                      - name: instrument_id
                        type: integer
                        required: false
                      - name: instrument
                        type: string
                        description: '`Example: BTC-PERP`'
                        examples: &ref_5
                          - BTC-PERP
                        required: false
                      - name: trade_id
                        type: integer
                        description: >-
                          Hotstuff L1 trade id, this is not always strictly
                          guaranteed to be unique
                        required: false
                      - name: tx_hash
                        type: string
                        description: Hotstuff L1 transaction hash
                        required: false
                      - name: side
                        type: string
                        description: '`b` if taker was buyer or `s` if taker was seller'
                        examples: &ref_6
                          - b
                          - s
                        required: false
                      - name: price
                        type: string
                        required: false
                      - name: size
                        type: string
                        required: false
                      - name: maker
                        type: string
                        description: maker address
                        required: false
                      - name: taker
                        type: string
                        description: taker address
                        required: false
                      - name: timestamp
                        type: integer
                        required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              x-parser-schema-id: <anonymous-schema-313>
            method:
              type: string
              x-parser-schema-id: <anonymous-schema-314>
            params:
              type: object
              properties:
                channel:
                  type: string
                  x-parser-schema-id: <anonymous-schema-316>
                data:
                  type: object
                  properties:
                    instrument_id:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-318>
                    instrument:
                      type: string
                      description: '`Example: BTC-PERP`'
                      examples: *ref_5
                      x-parser-schema-id: <anonymous-schema-319>
                    trade_id:
                      type: integer
                      description: >-
                        Hotstuff L1 trade id, this is not always strictly
                        guaranteed to be unique
                      x-parser-schema-id: <anonymous-schema-320>
                    tx_hash:
                      type: string
                      description: Hotstuff L1 transaction hash
                      x-parser-schema-id: <anonymous-schema-321>
                    side:
                      type: string
                      description: '`b` if taker was buyer or `s` if taker was seller'
                      examples: *ref_6
                      x-parser-schema-id: <anonymous-schema-322>
                    price:
                      type: string
                      x-parser-schema-id: <anonymous-schema-323>
                    size:
                      type: string
                      x-parser-schema-id: <anonymous-schema-324>
                    maker:
                      type: string
                      description: maker address
                      x-parser-schema-id: <anonymous-schema-325>
                    taker:
                      type: string
                      description: taker address
                      x-parser-schema-id: <anonymous-schema-326>
                    timestamp:
                      type: integer
                      x-parser-schema-id: <anonymous-schema-327>
                  x-parser-schema-id: <anonymous-schema-317>
              x-parser-schema-id: <anonymous-schema-315>
          x-parser-schema-id: <anonymous-schema-312>
        title: Channel event
        description: Server-pushed JSON-RPC event
        example: |-
          {
            "jsonrpc": "2.0",
            "method": "event",
            "params": {
              "channel": "trades:BTC-PERP",
              "data": {
                "instrument_id": 1,
                "instrument": "BTC-PERP",
                "trade_id": 1977789105883768800,
                "tx_hash": "0x7f3f0051f155a58a9362882ec3fe01162d0c2c3123d32fc87f89ac31ab039c4d",
                "side": "b",
                "price": "67804",
                "size": "0.00303",
                "maker": "0x14191D72B99Fb42E712360eF518e983e87d551Ec",
                "taker": "0xeE1c303b69Fe40B74BB7c2408e99C5415928EFcb",
                "timestamp": 1770859894258
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
    bindings: []
    extensions: *ref_7
sendOperations:
  - *ref_8
receiveOperations:
  - *ref_9
sendMessages:
  - *ref_10
receiveMessages:
  - *ref_11
extensions:
  - id: x-parser-unique-object-id
    value: trades
securitySchemes: []

````

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