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

# Market Stats

> Consolidated BBO, mark price, open interest, funding, and rolling 24-hour volume snapshots.

Subscribe to consolidated market statistics for one symbol or all symbols.

The `market_stats` stream combines the latest BBO, mark price, open interest, funding rate, and rolling 24-hour traded quantity and notional volume into one message.

On subscribe, MDS sends a `subscribed` acknowledgement, followed by a snapshot when data is available. Named-symbol subscriptions refresh once per second. Wildcard subscriptions (`symbols: ["*"]`) now refresh every 10 seconds. Each message is a complete snapshot for the requested symbol or symbols, so clients can replace the previous snapshot rather than applying a delta.

## How it works

Connect to the public websocket:

* URL: `wss://mds.qfex.com`
* Authentication: not required.

Then send a subscribe message:

```json theme={null}
{
  "type": "subscribe",
  "channels": ["market_stats"],
  "symbols": ["AAPL-USD"]
}
```

Or subscribe to all symbols with a wildcard:

```json theme={null}
{ "type": "subscribe", "channels": ["market_stats"], "symbols": ["*"] }
```

When `market_stats` is the only channel in the request, omitting `symbols` or sending an empty array also subscribes to all symbols:

```json theme={null}
{ "type": "subscribe", "channels": ["market_stats"] }
```

For multiple named symbols, MDS sends a separate snapshot for each symbol. A wildcard subscription receives one snapshot containing all available symbols, with the top-level `symbol` set to `"*"`.

## Sample code

```python python theme={null}
# Python (websocket-client)
import json
import websocket

def on_open(ws):
    sub = {
        "type": "subscribe",
        "channels": ["market_stats"],
        "symbols": ["*"]
    }
    ws.send(json.dumps(sub))

def on_message(ws, message):
    print("Market stats:", message)

if __name__ == "__main__":
    ws = websocket.WebSocketApp(
        "wss://mds.qfex.com",
        on_open=on_open,
        on_message=on_message
    )
    ws.run_forever()
```

```javascript node theme={null}
// Node.js (ws)
import WebSocket from "ws";

const ws = new WebSocket("wss://mds.qfex.com");

ws.on("open", () => {
  const sub = {
    type: "subscribe",
    channels: ["market_stats"],
    symbols: ["*"],
  };
  ws.send(JSON.stringify(sub));
});

ws.on("message", (msg) => {
  console.log("Market stats:", msg.toString());
});
```

## Example response

This illustrative wildcard snapshot contains one symbol:

```json theme={null}
{
  "type": "market_stats",
  "sequence": 30272540,
  "time": "2025-09-04T09:26:40Z",
  "symbol": "*",
  "bbos": [
    {
      "time": "2025-09-04T09:26:39.545268322Z",
      "symbol": "AAPL-USD",
      "bid": [["10101.1", "0.4505414"]],
      "ask": [["10102.55", "0.57753524"]]
    }
  ],
  "mark_prices": [
    {
      "time": "2025-09-04T09:26:39.545268322Z",
      "symbol": "AAPL-USD",
      "price": "10102"
    }
  ],
  "open_interests": [
    {
      "time": "2025-09-04T09:26:39.545268322Z",
      "symbol": "AAPL-USD",
      "open_interest": "12.5"
    }
  ],
  "funding_rates": [
    {
      "time": "2025-09-04T09:26:39.545268322Z",
      "symbol": "AAPL-USD",
      "funding_rate": "0.00001",
      "annualised_funding_rate": "0.0876",
      "time_remaining": 200
    }
  ],
  "daily_volumes": [
    {
      "symbol": "AAPL-USD",
      "volume": "12.5"
    }
  ],
  "daily_volumes_notional": [
    {
      "symbol": "AAPL-USD",
      "volume": "126275"
    }
  ]
}
```

## Response fields

| Field | Description |
| - | - |
| `type` | Always `"market_stats"`. |
| `sequence` | Sequence number shared with other market-data messages on this connection. |
| `time` | UTC timestamp when the snapshot was built. Individual components retain their own latest timestamps. |
| `symbol` | The requested symbol, or `"*"` for an all-symbol snapshot. |
| `bbos` | Latest [best bid and offer](https://docs.qfex.com/websocket/channels/mds/bbo.md) for each available symbol. Each quote is a `[price, quantity]` pair of decimal strings. |
| `mark_prices` | Latest [mark price](https://docs.qfex.com/websocket/channels/mds/mark_price.md) for each available symbol. |
| `open_interests` | Latest [open interest](https://docs.qfex.com/websocket/channels/mds/open_interest.md) for each available symbol. |
| `funding_rates` | Latest [funding](https://docs.qfex.com/websocket/channels/mds/funding_rate.md) for each available symbol: `funding_rate`, `annualised_funding_rate`, and `time_remaining` in seconds. Rates are decimal strings, not percentage strings. |
| `daily_volumes` | Rolling 24-hour traded quantity. Each entry contains `symbol` and a decimal-string `volume`. |
| `daily_volumes_notional` | Rolling 24-hour traded notional in USD. Each entry contains `symbol` and a decimal-string `volume`. |

The six component fields are always arrays and can be empty when a latest value is unavailable. Join entries by `symbol`; the arrays may contain different sets of symbols. Prices, quantities, open interest, volumes, and funding rates are serialized as decimal strings.

### Unsubscribe (optional)

```json theme={null}
{ "type": "unsubscribe", "channels": ["market_stats"], "symbols": ["*"] }
```

***

**Notes**

* `symbols` supports a single symbol, multiple symbols, or wildcard `"*"`.
* The `daily_volumes` and `daily_volumes_notional` names are retained for compatibility. Both measure the previous 24 hours and have no fixed daily reset. They can decrease as older trades leave the window.
* Snapshots are sent only when at least one component has data. Component timestamps can be older than the snapshot timestamp.
* `market_stats` ignores `intervals` and `sig_figs`; it always uses the default subscription filter.


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