# Activity Feed

Use this stream for live trades and position-related activity by event outcome.

### Endpoint

```
wss://history-service.outpoll.com/history/ws
```

### Authentication

No authentication required.

### Message envelope

```json
{
  "t": "<TYPE>",
  "e": "<EVENT_ID>",
  "o": "<OUTCOME_ID>",
  "d": { ... },
  "r": "<ERROR_MESSAGE>"
}
```

| Field | Type   | Description   |
| ----- | ------ | ------------- |
| `t`   | string | Message type  |
| `e`   | string | Event ID      |
| `o`   | string | Outcome ID    |
| `d`   | object | Event payload |
| `r`   | string | Error message |

### Subscribe

```json
{
  "t": "SUBSCRIBE",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"
}
```

### Unsubscribe

```json
{
  "t": "UNSUBSCRIBE",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"
}
```

### Common errors

```json
{
  "t": "error",
  "e": "event-id",
  "o": ["outcome-id"],
  "d": {
    "error": "Error description"
  }
}
```

| Error                   | Cause                         |
| ----------------------- | ----------------------------- |
| No outcome IDs provided | Subscribe without outcome IDs |
| Unknown message type    | Unsupported `t` value         |

### Python example

{% code title="activity\_feed.py" %}

```python
import asyncio, json, websockets

async def activity_feed():
    uri = "wss://history-service.outpoll.com/history/ws"
    async with websockets.connect(uri) as ws:
        await ws.send(json.dumps({
            "t": "SUBSCRIBE",
            "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
            "o": "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76",
        }))

        async for msg in ws:
            print(json.loads(msg))
```

{% endcode %}
