> For the complete documentation index, see [llms.txt](https://docs.pretoke.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pretoke.xyz/how-it-works/live-updates.md).

# Live Updates (WebSocket)

Prices, order books, and your own balance/positions all update in real time without you refreshing the page. This is powered by a WebSocket connection running alongside the regular API.

## What updates live

* **Market prices** — as trades happen anywhere on the platform, prices on the market you're viewing update instantly.
* **Order book depth** — the resting buy/sell orders you see update as orders are placed, filled, or cancelled.
* **Your balance and positions** — the moment your own trade fills, your portfolio numbers update without needing a page reload.

## How it's built (for the curious)

The platform runs a single WebSocket endpoint that the frontend connects to once you load the app. It supports three kinds of subscriptions:

* **Market channel** — general price/volume updates for one or more markets.
* **Book channel** — detailed order book updates for a specific market, including an initial full snapshot the moment you subscribe so you're never looking at stale data while waiting for the first update.
* **User channel** — private updates just for your account (balance and position changes), which requires your session token to subscribe to, since this is your private data.

The frontend automatically subscribes to whatever's relevant to the page you're on — for instance, opening a market page subscribes you to that market's price and order book channels; connecting your wallet subscribes you to your private user channel.

## If your connection drops

The frontend automatically reconnects and resubscribes if your WebSocket connection is interrupted — you might see a brief pause in live updates, but the regular polling that also runs alongside the WebSocket (as a backup) keeps things reasonably fresh even during a reconnect.

For the exact message formats if you're building an integration, see the [WebSocket API Reference](/api-reference/websocket.md).


---

# 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.pretoke.xyz/how-it-works/live-updates.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.
