> For the complete documentation index, see [llms.txt](https://docs.hypertracker.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hypertracker.io/websocket-streams/replaying-missed-data.md). Agents can also search and read this documentation through its [MCP server](https://docs.hypertracker.io/~gitbook/mcp).

# Replaying Missed Data

## Replaying missed data

`rooms:fills`, `rooms:misc_events`, and `rooms:twaps` support replay. `orders:feed` is live only. Use REST history to catch up orders.

Replay continues after a saved position. It does not return the last N events.

### How it works

1. Save the channel `epoch` and each processed event `offset`.
2. Reconnect and subscribe with `recover: true`, `epoch`, and `offset`.
3. Process the missed events, then live events.

SDKs replay automatically on reconnect. Use `since` only after an application restart.

### Limits

* Replay covers the last 5,000 messages, up to 10 minutes.
* `recovered: false` means the gap remains. No error is returned.
* An epoch change prevents replay.
* Large gaps can close with `3010 insufficient state`. Subscribe fresh.
* Filters do not increase replay capacity.

### Plain WebSocket

```js
const subscribe = { channel: 'rooms:fills' };
subscribe.recover = true;
subscribe.epoch = EPOCH;
subscribe.offset = OFFSET;
ws.send(JSON.stringify({ id: 2, subscribe }));

// In the subscribe reply, recovered events are inline:
for (const pub of msg.subscribe.publications ?? []) {
  console.log('(recovered)', pub.data);
}
```

Advance `OFFSET` only after processing each live publication. Persist the latest position.

### SDK

```js
const sub = client.newSubscription('rooms:fills', {
  since: { epoch: EPOCH, offset: OFFSET },
});
sub.on('subscribed', (ctx) => {
  console.log(ctx.streamPosition, ctx.recovered, ctx.hasRecoveredPublications);
});
sub.on('publication', (ctx) => console.log(ctx.offset, ctx.data));
```

The SDK sends recovered publications through the normal handler. They follow `subscribed` and precede live events.

{% hint style="warning" %}
Replay handles brief interruptions only. Save positions frequently. Always deduplicate by `id`.
{% endhint %}

If Python SDK `since` support is unavailable, use a plain WebSocket.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hypertracker.io/websocket-streams/replaying-missed-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
