> For the complete documentation index, see [llms.txt](https://docs.outpoll.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.outpoll.com/api/rest-api/websockets/chance-history.md).

# Chance History

Use this stream for live probability updates and chart backfill.

### Endpoint

```
wss://chance-history-service.outpoll.com/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 IDs                    |
| `d`   | object    | Message payload                |
| `r`   | string    | Error message for failed calls |

### Subscribe

```json
{
  "t": "SUBSCRIBE",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": [
    "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76",
    "97b06d16-aeff-4dd4-b08b-1ba30a2b8895"
  ]
}
```

After subscribe, the server sends:

1. `probability` with the latest known value
2. `success` with subscribe confirmation

### Live updates

#### Probability update

```json
{
  "t": "probability",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": ["b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"],
  "d": {
    "t": 1712160300,
    "p": 0.67
  }
}
```

#### History update

```json
{
  "t": "UPDATE_HISTORY",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": ["b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"],
  "d": {
    "t": 1712160300,
    "p": 0.67
  }
}
```

| Field | Type   | Description                     |
| ----- | ------ | ------------------------------- |
| `d.t` | number | Unix timestamp in seconds       |
| `d.p` | number | Probability from `0.0` to `1.0` |

### Unsubscribe

```json
{
  "t": "UNSUBSCRIBE",
  "o": [
    "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"
  ]
}
```

Success response:

```json
{
  "t": "success",
  "o": ["b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"],
  "d": { "message": "unsubscribe successful" }
}
```

### Request history

```json
{
  "t": "HISTORY",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": [
    "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"
  ],
  "d": {
    "p": "1H",
    "f": "2026-01-01T00:00:00Z",
    "t": "2026-01-01T12:00:00Z"
  }
}
```

#### Supported periods

| Code  |
| ----- |
| `1s`  |
| `5s`  |
| `5M`  |
| `10M` |
| `30M` |
| `1H`  |
| `3H`  |
| `4H`  |
| `6H`  |
| `1d`  |
| `7d`  |
| `1m`  |

You can also pass a custom number of seconds as a string.

### History response

```json
{
  "t": "HISTORY_RESPONSE",
  "e": "54ccea1a-16fd-469c-8018-84b375243e8a",
  "o": ["b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76"],
  "d": {
    "b21f6fd8-b9d1-4b9f-bb79-ef141e3dcb76": [
      { "t": 1735689600, "p": 0.50 },
      { "t": 1735693200, "p": 0.52 },
      { "t": 1735696800, "p": 0.55 }
    ]
  }
}
```

Each point includes:

| Field | Type   | Description             |
| ----- | ------ | ----------------------- |
| `t`   | number | Period end in Unix time |
| `p`   | number | Close probability value |

{% hint style="info" %}
The first point is an anchor value at or before `from`. If no data exists in range, the service returns a flat line.
{% endhint %}

### REST parity

The same history is available over REST:

```
GET /api/events/{eventId}/outcomes/{outcomeId}/history
```

### Python example

{% code title="chance\_history.py" %}

```python
import asyncio, json, websockets

async def chart_stream():
    uri = "wss://chance-history-service.outpoll.com/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:
            data = json.loads(msg)
            print(data["t"], data["d"])
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.outpoll.com/api/rest-api/websockets/chance-history.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
