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

# Stream Prediction Orders

> Streams one account's prediction-market orders as server-sent events: its working orders first, then every change to its orders as it happens.

**Use Case:** Keep an order blotter current, and show acknowledgements, fills, cancellations, and rejections as they arrive, without polling.


<Warning>
  This endpoint is in **closed beta**. It is available only to accounts enrolled in the beta, and only on staging (`https://api.tradearies.dev`). Request and response shapes may change before general availability.
</Warning>

## Request

```text theme={null}
GET /v1/predictions/orders/stream?accountId=ACCOUNT-0001
```

| Parameter | Description |
| - | - |
| `accountId` | Required. The account whose orders to stream. |

Authenticate the same way as the other order endpoints. The stream carries only the authenticated user's own orders: an account you have no orders on streams an empty snapshot and nothing after it.

## Events

| Event | When | Payload |
| - | - | - |
| `snapshot` | First, once | `accountId` and `orders`: the account's open orders |
| `order` | Each time one of the account's orders changes | One order |
| `resync` | When the stream is about to end | `reason`: `slow_client` or `shutdown` |

A `: ping` comment is sent every 15 seconds to keep idle connections open.

### snapshot

```json theme={null}
{
  "accountId": "ACCOUNT-0001",
  "orders": [
    {
      "orderId": "0b9f3c2e-5d6a-4f1b-8e7c-9a0d1e2f3a4b",
      "accountId": "ACCOUNT-0001",
      "symbol": "HORC_1126_Republican",
      "outcome": "YES",
      "side": "buy",
      "orderType": "limit",
      "timeInForce": "day",
      "quantity": "10",
      "price": "0.54",
      "workingQuantity": "10",
      "state": "new",
      "cumQty": "0",
      "leavesQty": "10",
      "avgPx": "0",
      "createdAt": "2026-10-08T14:02:11.482Z",
      "updatedAt": "2026-10-08T14:02:11.497Z",
      "version": 2
    }
  ]
}
```

`orders` holds every order on the account in an open state: `pending_new`, `new`, `partially_filled`, or `unknown`. Each order has the same shape as `data.order` in [Get Prediction Order](/api-reference/predictions/get-order).

### order

```json theme={null}
{
  "orderId": "0b9f3c2e-5d6a-4f1b-8e7c-9a0d1e2f3a4b",
  "accountId": "ACCOUNT-0001",
  "symbol": "HORC_1126_Republican",
  "outcome": "YES",
  "side": "buy",
  "orderType": "limit",
  "timeInForce": "day",
  "quantity": "10",
  "price": "0.54",
  "workingQuantity": "10",
  "state": "partially_filled",
  "cumQty": "4",
  "leavesQty": "6",
  "avgPx": "0.54",
  "createdAt": "2026-10-08T14:02:11.482Z",
  "updatedAt": "2026-10-08T14:02:15.103Z",
  "version": 3
}
```

Each `order` is the whole order as it stands after the change, not a delta: replace what you hold for that `orderId`. Orders reaching a final state (`filled`, `canceled`, `rejected`, `expired`, `done_for_day`) arrive this way too, and so do orders placed after you connected.

### resync

```json theme={null}
{ "reason": "slow_client" }
```

The stream ends right after a `resync`. Reconnect, and the new `snapshot` brings your view up to date. `slow_client` means you stopped reading events fast enough to keep up; `shutdown` means the server is restarting.

## Ordering

* Every order carries a `version` that rises with each change. **Keep the highest `version` you have seen for each `orderId`, and ignore an order at or below it.** The stream already drops older versions, but applying this rule makes your client correct across reconnects too.
* `snapshot` comes first. Every `order` after it is newer than the snapshot's copy of that order.
* Changes to one order arrive in the order they happened. Changes to different orders may interleave.

## Reconnecting

Events have no IDs and are not replayed. Every connection starts with a fresh `snapshot`, so after a disconnect or a `resync`, reconnect and replace your open orders with the new snapshot. A change that happened while you were disconnected is reflected in it. An order that reached a final state while you were away drops out of the snapshot; read it with [List Prediction Orders](/api-reference/predictions/list-orders) if you need it.

## Examples

```bash cURL theme={null}
curl -N "https://api.tradearies.dev/v1/predictions/orders/stream?accountId=ACCOUNT-0001" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

A browser's `EventSource` cannot send an `Authorization` header, so read the stream with `fetch`:

```javascript JavaScript theme={null}
const orders = new Map();

function apply(order) {
  const held = orders.get(order.orderId);
  if (!held || order.version > held.version) orders.set(order.orderId, order);
}

async function streamOrders(accountId, accessToken) {
  const res = await fetch(
    `https://api.tradearies.dev/v1/predictions/orders/stream?accountId=${encodeURIComponent(accountId)}`,
    { headers: { Authorization: `Bearer ${accessToken}` } }
  );
  if (!res.ok) throw new Error(`stream refused: ${res.status}`);

  const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
  let buffer = "";
  for (;;) {
    const { value, done } = await reader.read();
    if (done) return; // the stream ended: reconnect
    buffer += value;
    let end;
    while ((end = buffer.indexOf("\n\n")) >= 0) {
      const frame = buffer.slice(0, end);
      buffer = buffer.slice(end + 2);
      const event = frame.match(/^event: (.*)$/m)?.[1];
      const data = frame.match(/^data: (.*)$/m)?.[1];
      if (event === "snapshot") {
        orders.clear();
        JSON.parse(data).orders.forEach(apply);
      } else if (event === "order") {
        apply(JSON.parse(data));
      }
    }
  }
}
```

## Working with the stream

* **Prices and quantities are decimal strings.** `"0.54"`, not `0.54`. Parse them with a decimal type.
* **Optional fields are omitted when absent**, never sent as zero.
* **Do not put the stream behind a buffering proxy.** Events must reach you as they are sent.

## Errors

Errors are returned before the stream opens, in the usual [error envelope](/prediction-api/overview#response-envelope):

| Status | `code` | When |
| - | - | - |
| `400` | `INVALID_STREAM_REQUEST` | `accountId` is missing. |
| `401` | — | Missing or invalid credentials. |
| `500` | `ORDER_STREAM_FAILED` | Unexpected server error. |
| `503` | `ORDER_STREAM_UNAVAILABLE` | The server is restarting or busy; retry shortly. |


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