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

> ## Agent Instructions
> To integrate AGG, start with Quickstart: REST (https://docs.agg.market/quickstart/rest), then Order lifecycle & statuses (https://docs.agg.market/concepts/order-lifecycle).
> Track every trade until it reaches a terminal status. Before retrying a failed or timed-out call, read Errors, retries & idempotency (https://docs.agg.market/concepts/errors).
> The API reference is generated from https://docs.agg.market/openapi/openapi.json.

# Orderbook streams

> Keep today's socket, or move the orderbook channel to its own URL, and choose the 100 ms or realtime tier

The orderbook channel can stay on the same socket as every other channel, or move to a second socket. Either way, `orderbook_snapshot` and `orderbook_delta` are unchanged. Field order, levels, and checksums are the ones on [WebSocket Protocol](https://docs.agg.market/api/websocket.md#1-orderbook-stream).

## Tiers

There are two tiers.

* **Conflated (default).** At most one delta per book per 100 ms. That delta is the net change since the previous conflated delta for that book. This is the cadence a client already gets on `wss://ws.agg.market/ws`.
* **Realtime.** Opt in per subscribe. Each accepted change is delivered as it happens.

Omit `latency`, or set it to `"conflated"`, for the default. Set it to `"realtime"` to opt in. One socket can hold some outcomes on each tier. The field applies only to the outcomes in that subscribe.

`seq` is counted separately on each tier. Do not compare a conflated `seq` with a realtime `seq` for the same outcome. `checksum` is the book state, so the same state has the same checksum on both tiers. Apply messages with [Sequencing and resync](https://docs.agg.market/api/websocket.md#sequencing-and-resync): a delta applies only when its `seq` is exactly one past the book, and every `orderbook_snapshot` replaces the book, whatever its `seq` is.

`resnapshot` is unchanged. It refreshes an outcome you are already subscribed to, on the tier that subscribe chose. It does not take `latency`.

The shared socket at `wsUrl` does not offer this choice. Adding `latency` there does not turn on realtime.

## The orderbook socket

`orderbookUrl` and `orderbookLatency` are options on `createAggClient`. Hooks and UI components use that client. They do not take a separate URL.

| `orderbookUrl` | What the orderbook channel does |
| - | - |
| Unset | Today's single socket. Orderbook shares `wsUrl` (`wss://ws.agg.market/ws`) with trades, arbitrage, catalog, and user events. |
| Set | A second socket. Only the orderbook channel uses `orderbookUrl`. Trades, arbitrage, catalog, and user events stay on `wsUrl`. |

```typescript theme={null}
import { createAggClient } from "@agg-build/sdk";

const client = createAggClient({
  baseUrl: "https://api.agg.market",
  appId: "your-app-id",
  wsUrl: "wss://ws.agg.market/ws",
  orderbookUrl: "wss://ob.agg.market/ws",
  // "conflated" (default) or "realtime". Sent as `latency` on subscribe.
  orderbookLatency: "conflated",
});
```

`orderbookLatency` defaults to `"conflated"`. `"realtime"` is sent as the optional `latency` field. The SDK still applies snapshots and deltas, checks `seq` and `checksum`, and runs the book watchdog. See [Real-Time Orderbook](https://docs.agg.market/recipes/websocket-orderbook.md).

This is a connection change, not a wire change. A raw client opens the orderbook socket the same way as the shared one, including `appId`:

```javascript theme={null}
const ws = new WebSocket(`wss://ob.agg.market/ws?appId=${appId}`);
```

Wait for `connected`. Browser and server handshakes match [Getting connected](https://docs.agg.market/api/websocket.md#getting-connected). A browser is admitted by an allowed `Origin`. A server sends `x-app-api-key` on the handshake. An API key is not required for the per-outcome orderbook channel.

## Subscribe

Subscriptions stay keyed by outcome id (`outcomes[].id`), not by market id. The same [snapshot unavailable](https://docs.agg.market/api/websocket.md#initial-snapshot) error applies when the id does not resolve.

```json theme={null}
{
  "action": "subscribe",
  "channel": "orderbook",
  "outcomeIds": ["vmo_1"],
  "latency": "realtime"
}
```

Leave `latency` off, or send `"conflated"`, for the 100 ms tier. The `subscribed` ack, `orderbook_snapshot`, and `orderbook_delta` that follow use the same objects as the [orderbook stream](https://docs.agg.market/api/websocket.md#initial-snapshot). A snapshot carries the `seq` of the tier you subscribed.

To stream every non-empty book on a venue from your backend, use the [Orderbook firehose](https://docs.agg.market/recipes/orderbook-firehose.md). That channel is separate. It stays off until Snag enables it, and it requires an app API key.

## Related

> [card] [WebSocket Protocol](https://docs.agg.market/api/websocket.md)
>
> Snapshot and delta objects, sequencing, resnapshot, and close codes.

> [card] [Real-Time Orderbook](https://docs.agg.market/recipes/websocket-orderbook.md)
>
> SDK, hooks, and UI components that keep the book for you.

> [card] [Orderbook firehose](https://docs.agg.market/recipes/orderbook-firehose.md)
>
> Every book on a venue, from a backend, after Snag enables it.

> [card] [Base URL and API keys](https://docs.agg.market/environments.md)
>
> The shared socket, app id, and server API key.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.