> For the complete documentation index, see [llms.txt](https://docs.strixlab.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.strixlab.io/developers/websocket-api.md).

# WebSocket API

Single endpoint: `wss://api.strixlab.io/ws`

All channels share **one connection**, and there's no limit on how many tokenIds you can subscribe to. On connect the server sends `{ "type": "connected" }` and pings every 30 seconds — respond with `{ "type": "pong" }` to stay alive.

## Order Book Channel · Public

**Subscribe:**

```json
{ "type": "subscribe", "markets": ["0x1a2b...", "0x3c4d..."], "depth": 50 }
```

**Messages:**

```jsonc
// Full snapshot — on subscribe and after significant state changes
{ "type": "orderbook.snapshot", "marketId": "0x1a2b...",
  "levels": { "bids": [{ "price": 0.62, "size": 500 }], "asks": [{ "price": 0.63, "size": 200 }] },
  "ts": 1716000000000 }

// Incremental update — size: 0 means remove the level
{ "type": "orderbook.delta", "marketId": "0x1a2b...", "side": "bid", "price": 0.62, "size": 350, "ts": 1716000000000 }

// Last trade price — fired on every settlement
{ "type": "last_trade_price", "marketId": "0x1a2b...", "price": 0.625, "size": 100, "ts": 1716000000000 }

// Market paused or resolved
{ "type": "market.status_update", "marketId": "0x1a2b...", "status": "PAUSE", "ts": 1716000000000 }
```

**Unsubscribe:** `{ "type": "unsubscribe", "markets": ["0x1a2b..."] }`

{% hint style="info" %}
Apply a `snapshot` as your baseline, then merge each `delta` at its price level (a `size` of `0` removes the level). Re-request a snapshot if you ever detect a gap.
{% endhint %}

## Trades Channel · Public

**Subscribe:** `{ "type": "subscribe", "channel": "trades", "markets": ["0x1a2b..."] }`

```json
{ "type": "trade.executed", "tokenId": "0x1a2b...", "price": 0.625, "size": 100, "side": "BUY", "ts": 1716000000000 }
```

`side` is the **taker's** side — a `BUY` trade consumed sell-side liquidity.

## User Channel · Auth

Authenticate over the socket, then you're auto-subscribed to your own events (no extra subscribe needed).

{% tabs %}
{% tab title="HMAC (bots)" %}

```json
{
  "type": "auth",
  "apiKey": "your_api_key",
  "passphrase": "your_passphrase",
  "timestamp": "1716000000",
  "signature": "<base64 HMAC-SHA256(secret, timestamp + 'GET' + '/ws')>"
}
```

Signature: `message = timestamp + "GET" + "/ws"`, then `base64(HMAC-SHA256(apiSecret, message))`.
{% endtab %}

{% tab title="Privy Bearer" %}

```json
{ "type": "auth", "token": "<privy_identity_token>" }
```

{% endtab %}
{% endtabs %}

**Messages:**

```jsonc
// Order partially or fully filled
{ "type": "order.update", "data": {
  "id": "ord_abc", "orderHash": "0xdeadbeef...", "status": "PARTIALLY_FILLED",
  "filledQuantity": 50, "remaining": 50, "price": 0.62, "side": "BUY", "marketId": "mkt_abc" } }

// On-chain settlement confirmed
{ "type": "trade.settled", "tradeId": "trd_abc", "side": "BUY", "price": 0.62, "quantity": 50, "txHash": "0x..." }

// Fill failed on-chain
{ "type": "trade.failed", "reason": "...", "marketId": "mkt_abc", "side": "BUY", "quantity": 100 }

// Cash balance updated after every fill
{ "type": "portfolio.summary_update", "data": {
  "cashBalance": "1188.50", "positionsValue": "461.00", "totalBalance": "1649.50" } }

// Optimistic position delta — fires ~15s before on-chain indexing catches up
{ "type": "position.update", "data": {
  "marketId": "mkt_abc", "outcomeId": "out_yes", "sharesDelta": 50, "averagePrice": 0.62 } }
```

{% hint style="info" %}
Order lifecycle over the socket: an `order.update` may carry a transient `MATCHED` status when the engine matches your order, followed by `trade.settled` once the on-chain settlement confirms. Treat `position.update` as optimistic — it's reconciled against on-chain state moments later.
{% endhint %}


---

# 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.strixlab.io/developers/websocket-api.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.
