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

# mids

Subscribe to real-time mid prices (average of best bid and ask) for trading instruments.

## Supported Symbols

* Individual markets: `BTC-PERP`, `ETH-PERP`, etc.
* All markets: `"all"`

## Example Request

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "subscribe",
  "params": {
    "channel": "mids",
    "symbol": "BTC-PERP" // support "all" or "BTC-PERP"
  }
}
```

## Example Response

```json theme={null}
{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "channel": "mids:BTC-PERP",
    "data": {
      "symbol": "BTC-PERP",
      "mid_price": 67887
    }
  }
}
```

## 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": "mids",
            "symbol": "BTC-PERP"  # or "all"
        }
    }
    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: "mids",
      symbol: "BTC-PERP", // or "all"
    },
  };
  ws.send(JSON.stringify(subscribeMsg));
};

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


## AsyncAPI

````yaml asyncapi/ws-subscriptions.json mids
id: mids
title: Mids
description: ''
servers:
  - id: production
    protocol: wss
    host: api.hotstuff.trade/ws
    bindings: []
    variables: []
address: /
parameters: []
bindings: []
operations:
  - &ref_6
    id: mids_sendSubscribe
    title: Mids_send subscribe
    type: receive
    messages:
      - &ref_8
        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: false
              - name: id
                type: integer
                description: Client request identifier
                examples: &ref_1
                  - 1
                required: false
              - name: method
                type: string
                description: Subscription action
                enumValues:
                  - subscribe
                  - unsubscribe
                examples: &ref_2
                  - subscribe
                required: false
              - name: params
                type: object
                description: Channel subscription parameters
                required: false
                properties:
                  - name: channel
                    type: string
                    description: Must be mids
                    examples: &ref_3
                      - mids
                    required: false
                  - name: symbol
                    type: string
                    description: 'Example: BTC-PERP'
                    examples: &ref_4
                      - BTC-PERP
                    required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              default: '2.0'
              examples: *ref_0
              description: JSON-RPC version
              x-parser-schema-id: <anonymous-schema-171>
            id:
              type: integer
              default: 1
              examples: *ref_1
              description: Client request identifier
              x-parser-schema-id: <anonymous-schema-172>
            method:
              type: string
              enum:
                - subscribe
                - unsubscribe
              default: subscribe
              examples: *ref_2
              description: Subscription action
              x-parser-schema-id: <anonymous-schema-173>
            params:
              type: object
              properties:
                channel:
                  type: string
                  description: Must be mids
                  default: mids
                  examples: *ref_3
                  x-parser-schema-id: <anonymous-schema-175>
                symbol:
                  type: string
                  description: 'Example: BTC-PERP'
                  default: BTC-PERP
                  examples: *ref_4
                  x-parser-schema-id: <anonymous-schema-176>
              description: Channel subscription parameters
              x-parser-schema-id: <anonymous-schema-174>
          x-parser-schema-id: <anonymous-schema-170>
        title: Subscription request
        description: Send subscribe/unsubscribe request
        example: |-
          {
            "jsonrpc": "2.0",
            "id": 1,
            "method": "subscribe",
            "params": {
              "channel": "mids",
              "symbol": "BTC-PERP"
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: a_subscribeRequest
    bindings: []
    extensions: &ref_5
      - id: x-parser-unique-object-id
        value: mids
  - &ref_7
    id: mids_receiveEvent
    title: Mids_receive event
    type: send
    messages:
      - &ref_9
        id: event
        contentType: application/json
        payload:
          - name: Mids 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: symbol
                        type: string
                        required: false
                      - name: mid_price
                        type: number
                        required: false
        headers: []
        jsonPayloadSchema:
          type: object
          properties:
            jsonrpc:
              type: string
              x-parser-schema-id: <anonymous-schema-178>
            method:
              type: string
              x-parser-schema-id: <anonymous-schema-179>
            params:
              type: object
              properties:
                channel:
                  type: string
                  x-parser-schema-id: <anonymous-schema-181>
                data:
                  type: object
                  properties:
                    symbol:
                      type: string
                      x-parser-schema-id: <anonymous-schema-183>
                    mid_price:
                      type: number
                      x-parser-schema-id: <anonymous-schema-184>
                  x-parser-schema-id: <anonymous-schema-182>
              x-parser-schema-id: <anonymous-schema-180>
          x-parser-schema-id: <anonymous-schema-177>
        title: Mids channel event
        description: Server-pushed JSON-RPC event
        example: |-
          {
            "jsonrpc": "2.0",
            "method": "event",
            "params": {
              "channel": "mids:BTC-PERP",
              "data": {
                "symbol": "BTC-PERP",
                "mid_price": 67887
              }
            }
          }
        bindings: []
        extensions:
          - id: x-parser-unique-object-id
            value: event
    bindings: []
    extensions: *ref_5
sendOperations:
  - *ref_6
receiveOperations:
  - *ref_7
sendMessages:
  - *ref_8
receiveMessages:
  - *ref_9
extensions:
  - id: x-parser-unique-object-id
    value: mids
securitySchemes: []

````

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