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

# Market Changes

> Server-Sent Events: the markets whose positions changed in each finalized batch, and crypto strike updates.

```
GET https://codex-api.nomos.trade/v1/stream
```

One long GET; events arrive as they happen. After each finalized batch Codex sends the markets whose positions changed: refetch what you show for them. It also sends every crypto strike state change.

A heartbeat comment (`: ping`) arrives every 15 s. There are no event ids, so after a reconnect, fill the gap with the matching REST route. At most 2 streams per key.

## Events

<ResponseField name="markets" type="event">
  <Expandable title="data">
    <ResponseField name="block" type="integer">The batch's last finalized block.</ResponseField>
    <ResponseField name="conditions" type="string[]">Condition ids whose positions changed, or that resolved, in the batch.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="strike" type="event">
  <Expandable title="data">
    <ResponseField name="slug" type="string">The round's market slug.</ResponseField>
    <ResponseField name="asset" type="string">btc, eth, sol, xrp, doge, bnb, hype or zec.</ResponseField>
    <ResponseField name="timeframe" type="string">5m, 15m, 1h, 4h or 1d.</ResponseField>
    <ResponseField name="start" type="integer">Round start, unix seconds.</ResponseField>
    <ResponseField name="state" type="string">scheduled, open, captured, confirmed, settled, disagree or missed.</ResponseField>
    <ResponseField name="strike" type="number | null">The price to beat, once confirmed.</ResponseField>
  </Expandable>
</ResponseField>

## The Stream

```text theme={null}
retry: 2000

event: markets
data: {"block":94812406,"conditions":["0x8db33416a2d1ebde7438c80129e898f89a5deb3852ca64b37c4bf46513204409"]}

: ping

event: strike
data: {"slug":"btc-updown-15m-1790862300","asset":"btc","timeframe":"15m","start":1790862300,"state":"confirmed","strike":112611.4}
```

## Read It

<CodeGroup>
  ```bash cURL theme={null}
  curl -N "https://codex-api.nomos.trade/v1/stream" \
    -H "Authorization: Bearer $CODEX_KEY"
  ```

  ```python Python theme={null}
  import json, os, requests

  with requests.get(
      "https://codex-api.nomos.trade/v1/stream",
      headers={"Authorization": f"Bearer {os.environ['CODEX_KEY']}"},
      stream=True,
      timeout=(10, 60),
  ) as r:
      r.raise_for_status()
      event = None
      for line in r.iter_lines(decode_unicode=True):
          if line.startswith("event: "):
              event = line[7:]
          elif line.startswith("data: "):
              print(event, json.loads(line[6:]))
  ```

  ```javascript JavaScript theme={null}
  // Node 18+
  const res = await fetch("https://codex-api.nomos.trade/v1/stream", {
    headers: { Authorization: `Bearer ${process.env.CODEX_KEY}` },
  });
  const decoder = new TextDecoder();
  let buffer = "";
  for await (const chunk of res.body) {
    buffer += decoder.decode(chunk, { stream: true });
    let end;
    while ((end = buffer.indexOf("\n\n")) >= 0) {
      const block = buffer.slice(0, end);
      buffer = buffer.slice(end + 2);
      const event = block.match(/^event: (.*)$/m)?.[1];
      const data = block.match(/^data: (.*)$/m)?.[1];
      if (event && data) console.log(event, JSON.parse(data));
    }
  }
  ```
</CodeGroup>


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