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

# Event Channel

> Receiving updates about specific events

## Overview

The `event` channel allows you to receive real-time updates about one or more specific events. Since an event can contain multiple markets, this channel is useful for monitoring all markets of an event at once.

## Authentication

The `event` channel **does not require authentication**. You can subscribe without providing an API key.

## Subscribe

To subscribe to the event channel:

```json theme={null}
{
  "type": "subscribe",
  "channel": "event",
  "events": ["event-id-1", "event-id-2"],
  "filter": "trades"
}
```

### Requirements

* **`events`** (required): Array of event IDs
* **`filter`** (optional): Desired update type
  * `""` or `"all"`: All updates (default)
  * `"orderbook"`: Only orderbook updates
  * `"trades"`: Only trade updates

### Examples

#### Receive All Updates

```json theme={null}
{
  "type": "subscribe",
  "channel": "event",
  "events": ["event-id-1"]
}
```

#### Receive Only Orderbook

```json theme={null}
{
  "type": "subscribe",
  "channel": "event",
  "events": ["event-id-1", "event-id-2"],
  "filter": "orderbook"
}
```

#### Receive Only Trades

```json theme={null}
{
  "type": "subscribe",
  "channel": "event",
  "events": ["event-id-1"],
  "filter": "trades"
}
```

## Received Messages

The received messages are identical to those from the [market channel](/en/websockets/market-channel), but include updates from all markets in the event.

### Orderbook Update

Received when there are changes to the orderbook of any market in the event (when `filter` is `"orderbook"` or `"all"`).

**Structure:**

```json theme={null}
{
  "msg_type": "update-orderbook",
  "event_id": "string",
  "market_id": "string",
  "orderbook": {
    // Same structure as orderbook from market channel
  }
}
```

### New Trade

Received when a new trade is executed on any market in the event (when `filter` is `"trades"` or `"all"`).

**Structure:**

```json theme={null}
{
  "msg_type": "new-trades",
  "event_id": "string",
  "market_id": "string",
  "last_trades": [
    {
    // Same structure as trade from market channel
  }
  ]
}
```

### Complete Update

Received when there are general updates to any market in the event (when `filter` is `"all"` or not specified).

**Structure:**

```json theme={null}
{
  "msg_type": "update",
  "event_id": "string",
  "market_id": "string",
  "orderbook": {
    // Same structure as orderbook from market channel
  },
  "last_trades": [
    {
    // Same structure as trade from market channel
  }
  ]
}
```

## Difference between Market and Event Channels

* **Market Channel**: Receives updates only from specified markets;
* **Event Channel**: Receives updates from all markets within specified events.

If an event has multiple markets, the `event` channel allows you to monitor all of them with a single subscription.

## Usage Example

<CodeGroup>
  ```javascript JavaScript theme={null}
  const ws = new WebSocket('wss://data-ws-dev.voxfi.com.br');

  ws.onopen = () => {
    // Subscribe to an event with orderbook filter
    ws.send(JSON.stringify({
      type: 'subscribe',
      channel: 'event',
      events: ['event-id-1'],
      filter: 'orderbook'
    }));
  };

  ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    
    if (data.msg_type === 'update-orderbook') {
      console.log(`Orderbook updated on event ${data.event_id}, market ${data.market_id}`);
      console.log('YES price:', data.orderbook.market_price_yes);
      console.log('NO price:', data.orderbook.market_price_no);
    } else if (data.msg_type === 'new-trades') {
      console.log(`New trades on event ${data.event_id}, market ${data.market_id}`);
      console.log('Trades:', data.last_trades);
    }
  };
  ```

  ```python Python theme={null}
  import asyncio
  import websockets
  import json

  async def subscribe_event():
      uri = "wss://data-ws-dev.voxfi.com.br"
      
      async with websockets.connect(uri) as websocket:
          # Subscribe to an event
          subscribe_msg = {
              "type": "subscribe",
              "channel": "event",
              "events": ["event-id-1"],
              "filter": "orderbook"
          }
          await websocket.send(json.dumps(subscribe_msg))
          
          # Receive messages
          async for message in websocket:
              data = json.loads(message)
              
              if data.get("msg_type") == "update-orderbook":
                  print(f"Orderbook updated on event {data['event_id']}, market {data['market_id']}")
                  print(f"YES price: {data['orderbook']['market_price_yes']}")
                  print(f"NO price: {data['orderbook']['market_price_no']}")
              elif data.get("msg_type") == "new-trades":
                  print(f"New trades on event {data['event_id']}, market {data['market_id']}")
                  print(f"Trades: {data['last_trades']}")

  asyncio.run(subscribe_event())
  ```
</CodeGroup>

## Unsubscribe

To unsubscribe from specific events:

```json theme={null}
{
  "type": "unsubscribe",
  "channel": "event",
  "events": ["event-id-1"]
}
```

## Use Cases

* **Complete Event Monitoring**: Monitor all markets of an event with a single subscription;
* **Comparative Analysis**: Compare prices and activity between different markets in the same event;
* **Event Dashboard**: Create a complete dashboard showing all markets of an event;
* **Event Alerts**: Set up alerts based on changes in any market of the event;
* **Correlation Analysis**: Analyze correlations between different markets in the same event.

## Best Practices

* **Use for Multi-Market Events**: The `event` channel is especially useful for events with multiple markets;
* **Specific Filters**: Use filters when you only need one type of update to reduce traffic;
* **Identification**: Always check both `event_id` and `market_id` in messages to correctly identify the source;
* **Performance**: For events with many markets, consider using filters to reduce message volume.
