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

**WebSocket URL:** `wss://api.hotstuff.trade/ws`

**Channel:** `mids`

## Parameters

| Parameter | Type | Required | Description | Example |
| - | - | - | - | - |
| `jsonrpc` | string | Yes | JSON-RPC version | `"2.0"` |
| `id` | string | Yes | Request identifier for tracking | `"1"` |
| `method` | string | Yes | Action to perform | `"subscribe"` or `"unsubscribe"` |
| `channel` | string | Yes | Channel name | `"mids"` |
| `symbol` | string | Yes | Trading symbol or "all" | `"BTC-PERP"`, `"ETH-PERP"`, `"all"` |

## Supported Methods

* `subscribe` - Subscribe to mid price updates
* `unsubscribe` - Unsubscribe from mid price updates

## Supported Symbols

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

## Example Request

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

## 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);
};
```


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