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

# Market Data WebSocket

> Real-time market price and state updates.

The Market Data WebSocket provides live updates for a specific market, including price changes, volume updates, and state transitions.

***

## Connection

```
wss://api.orica.markets/ws/markets/{market_address}
```

**market\_address** `string` *required*

The market address to subscribe to.

***

## Message Types

### Server Messages

> [tab] market
>
> Sent immediately on connection with full market data.
>
> ```json theme={"dark"}
> {
>   "type": "market",
>   "data": {
>     "address": "ABC123...",
>     "question": "Will Bitcoin hit $100k?",
>     "options": ["Yes", "No"],
>     "status": "open",
>     "outcome_pools": [1500000000, 2000000000],
>     "outcome_supplies": [15000, 20000],
>     "total_volume": 35000.50,
>     ...
>   }
> }
> ```

> [tab] history
>
> Sent after connection with historical price data.
>
> ```json theme={"dark"}
> {
>   "type": "history",
>   "interval": "1s",
>   "data": [
>     {
>       "timestamp": 1704067200,
>       "market_caps": [1500.00, 2000.00],
>       "supplies": [15000, 20000],
>       "volume": 35000.50
>     }
>   ]
> }
> ```

> [tab] update
>
> Sent when market state changes.
>
> ```json theme={"dark"}
> {
>   "type": "update",
>   "data": {
>     "timestamp": 1704067260,
>     "market_caps": [1550.00, 1980.00],
>     "supplies": [15500, 19800],
>     "volume": 35150.75
>   }
> }
> ```

> [tab] pong
>
> Response to client ping.
>
> ```json theme={"dark"}
> {
>   "type": "pong"
> }
> ```

> [tab] error
>
> Error message.
>
> ```json theme={"dark"}
> {
>   "type": "error",
>   "message": "Invalid interval"
> }
> ```

### Client Messages

> [tab] set\_interval
>
> Change the data interval.
>
> ```json theme={"dark"}
> {
>   "action": "set_interval",
>   "interval": "1m"
> }
> ```
>
> Valid intervals: `1s`, `1m`, `5m`, `15m`, `1h`, `4h`, `1d`

> [tab] ping
>
> Keep connection alive.
>
> ```json theme={"dark"}
> {
>   "action": "ping"
> }
> ```

***

## Connection Example

```typescript theme={"dark"}
const marketAddress = "ABC123...";
const ws = new WebSocket(`wss://api.orica.markets/ws/markets/${marketAddress}`);

ws.onopen = () => {
  console.log("Connected to market WebSocket");
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  
  switch (message.type) {
    case "market":
      console.log("Market data:", message.data);
      break;
    case "history":
      console.log(`Received ${message.data.length} historical points`);
      break;
    case "update":
      console.log("Price update:", message.data.market_caps);
      break;
    case "pong":
      console.log("Pong received");
      break;
    case "error":
      console.error("Error:", message.message);
      break;
  }
};

// Change interval to 1 minute
ws.send(JSON.stringify({ action: "set_interval", interval: "1m" }));

// Keep alive
setInterval(() => {
  if (ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ action: "ping" }));
  }
}, 30000);
```

***

## Data Points

Each update and history point contains:

| Field | Type | Description |
| - | - | - |
| `timestamp` | `number` | Unix timestamp (aligned to interval) |
| `market_caps` | `number[]` | Market cap for each outcome (USDC) |
| `supplies` | `number[]` | Share supply for each outcome |
| `volume` | `number` | Total volume at this point (USDC) |

***

## Gap Filling

Historical data is automatically gap-filled:

* Missing intervals are filled with the last known values
* Data extends forward to the current blockchain time
* Maximum of 60 data points returned

***

## Timeouts

| Event | Timeout |
| - | - |
| Idle connection | 5 minutes |
| No ping response | 60 seconds |
| Maximum connection | 1 hour |

Send periodic pings to keep the connection alive.


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