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

# Event and market status

> Receive status changes for events and their child markets

Connect to `wss://socket.bayse.markets/ws/v1/markets` and subscribe to the
`lifecycle` channel. No API key or HMAC signature is required. Each event
subscription includes the parent event and all its child markets.

## Subscribe

Subscribe to up to **50 events per request**:

```json theme={null}
{
  "type": "subscribe",
  "channel": "lifecycle",
  "eventIds": [
    "124d50eb-0d25-4026-a5f3-69df51768517",
    "06ec1292-f1c8-4387-928c-ed396946956f"
  ]
}
```

For one event, you can also use `eventId`:

```json theme={null}
{"type":"subscribe","channel":"lifecycle","eventId":"124d50eb-0d25-4026-a5f3-69df51768517"}
```

Use either `eventId` or `eventIds` in a request. Arrays must contain 1–50 valid
UUIDs. Duplicate entries count toward the limit and subscribe only once. Empty,
oversized, or invalid lists reject the entire request without changing your
subscriptions. The limit applies per request. You can send additional requests
for more events, subject to the [message rate limit](https://docs.bayse.markets/websocket/errors.md).

## Messages received

### Parent event changed

```json theme={null}
{
  "type": "event.status_changed",
  "data": {
    "eventId": "124d50eb-0d25-4026-a5f3-69df51768517",
    "status": "closed"
  },
  "timestamp": 1794230580360
}
```

### Child market changed

```json theme={null}
{
  "type": "market.status_changed",
  "data": {
    "eventId": "124d50eb-0d25-4026-a5f3-69df51768517",
    "marketId": "fbf1449c-ff60-4744-ab00-b1c686939cab",
    "status": "closed"
  },
  "timestamp": 1794230580370
}
```

`status` uses the API's lowercase values, such as `open`, `paused`, `closed`,
`resolved`, and `cancelled`. `timestamp` is the server send time in Unix
milliseconds. Each notification identifies one entity, including when you
subscribe with an array.

Lifecycle WebSocket events are typically delayed by up to one minute and carry
the latest status change for each entity.

Handle parent and child notifications independently. Closing or resolving an
event can also close or resolve its markets, producing both message types. A child market can resolve
while the parent remains open, producing only a market notification. Accept
either arrival order and refresh the affected event to obtain its current state.
A status notification does not confirm that payouts have completed. Changes to
outcomes or other fields without a status change do not produce this notification.

## Unsubscribe

Use the same fields with `type: "unsubscribe"`. The same validation and 50-entry
limit apply, and unrelated subscriptions remain active.

```json theme={null}
{
  "type": "unsubscribe",
  "channel": "lifecycle",
  "eventIds": ["124d50eb-0d25-4026-a5f3-69df51768517"]
}
```

The server returns one confirmation per unique event:

```json theme={null}
{
  "type": "unsubscribed",
  "room": "lifecycle:124d50eb-0d25-4026-a5f3-69df51768517",
  "message": "Unsubscribed from: lifecycle:124d50eb-0d25-4026-a5f3-69df51768517",
  "timestamp": 1794230640000
}
```

## Client examples

These examples print status notifications. A frame can contain several JSON
objects separated by newlines.

```javascript Node.js (22+) theme={null}
const ws = new WebSocket('wss://socket.bayse.markets/ws/v1/markets');
ws.addEventListener('open', () => {
  ws.send(JSON.stringify({
    type: 'subscribe',
    channel: 'lifecycle',
    eventIds: ['124d50eb-0d25-4026-a5f3-69df51768517'],
  }));
});
ws.addEventListener('message', ({ data }) => {
  for (const line of String(data).split('\n')) {
    if (!line.trim()) continue;
    try {
      const message = JSON.parse(line);
      if (message.type === 'error') console.error(message.message);
      if (['event.status_changed', 'market.status_changed'].includes(message.type)) {
        console.log(message.type, message.data);
      }
    } catch (error) {
      console.error('Could not parse message:', error);
    }
  }
});
ws.addEventListener('error', (error) => console.error('WebSocket error:', error));
ws.addEventListener('close', ({ code }) => console.log('Disconnected:', code));
```

```python Python theme={null}
# Install: pip install websockets
import asyncio
import json
import websockets
from websockets.exceptions import WebSocketException

async def main():
    try:
        async with websockets.connect('wss://socket.bayse.markets/ws/v1/markets') as ws:
            await ws.send(json.dumps({
                'type': 'subscribe',
                'channel': 'lifecycle',
                'eventIds': ['124d50eb-0d25-4026-a5f3-69df51768517'],
            }))
            async for frame in ws:
                for line in frame.splitlines():
                    if not line.strip():
                        continue
                    try:
                        message = json.loads(line)
                    except json.JSONDecodeError as error:
                        print('Could not parse message:', error)
                        continue
                    if message.get('type') == 'error':
                        print('Subscription error:', message.get('message'))
                    if message.get('type') in ('event.status_changed', 'market.status_changed'):
                        print(message['type'], message['data'])
    except (OSError, WebSocketException) as error:
        print('WebSocket error:', error)

asyncio.run(main())
```


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