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

# Backfill history

> Windows, countBack paging, the two signals that tell you to stop scrolling — and the handoff to the live stream.

[Get price history](/api-reference/market-data/get-price-history) has two modes, and picking the
wrong one is the usual cause of a chart that scrolls forever. A plain window answers "what
happened between these two times". `countBack` answers "give me the N bars before this point" —
the scroll-back page — and it outranks `from` when both are sent.

<Steps>
  <Step title="Ask for the default window">
    With no range at all, the route answers the most recent 500 bars or so. It is the fastest way
    to get something on screen.

    ```bash theme={null}
    curl "$TRDRS_API_BASE_URL/api/market/history?instrument=ESU6&tf=5m" \
      -H "Authorization: Bearer $TRDRS_TENANT_KEY"
    ```

    Bars come back as `{ t, o, h, l, c, v }` with `t` in epoch seconds.
  </Step>

  <Step title="Narrow it to a window">
    `from` and `to` are epoch seconds, inclusive at both ends.

    ```bash theme={null}
    curl "$TRDRS_API_BASE_URL/api/market/history?instrument=ESU6&tf=5m&from=1787500000&to=1787586400" \
      -H "Authorization: Bearer $TRDRS_TENANT_KEY"
    ```

    The window's width is capped in bars by `limits.maxBars` from [the limits
    route](/api-reference/market-data/get-market-data-limits) — the same number that caps
    `countBack`. Ask for a wider span at a finer timeframe and you are asking for more bars than
    the route will serve.
  </Step>

  <Step title="Page backwards with countBack">
    `countBack` asks for the last N bars at or before `to`. This is the call a chart makes when the
    user drags the view left.

    ```bash theme={null}
    curl "$TRDRS_API_BASE_URL/api/market/history?instrument=ESU6&tf=5m&to=1787500000&countBack=500" \
      -H "Authorization: Bearer $TRDRS_TENANT_KEY"
    ```

    Set `to` to the timestamp of the oldest bar you currently hold and ask again for the next page.
    `countBack` outranks `from`, so send `to` and `countBack` and leave `from` out of it.
  </Step>

  <Step title="Hand over to the stream">
    Once the backfill is on screen, [open a bar
    stream](/api-reference/market-data/stream-live-bars) for the same instrument and timeframe. On
    every connect the stream replays a full `snapshot` and then applies live `bar` events, so the
    two views converge without you reconciling them.

    ```bash theme={null}
    curl -N "$TRDRS_API_BASE_URL/api/market/stream?instrument=ESU6&tf=5m" \
      -H "Authorization: Bearer $TRDRS_TENANT_KEY"
    ```
  </Step>
</Steps>

## The two signals that end a scroll-back

Both are present only when they are true, so treat an absent field as false.

| Signal         | What it means                                                             | What to do                                                                                                         |
| -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `noData: true` | The `countBack` answer came back empty.                                   | Stop scrolling back. There is nothing older to fetch at this timeframe.                                            |
| `stale: true`  | Every bar served predates the asked `countBack` window — a closed market. | Render it as history, not as now. It is what stops a consumer mistaking Friday's bars for a live Saturday session. |

A chart that ignores `noData` keeps asking for pages that will never exist. A chart that ignores
`stale` shows a weekend as if the market were open.

## Spread expressions

The `instrument` may be an arithmetic expression over instruments rather than a single symbol —
`ES-NQ`, `1/ESU6`, `(ES+NQ)/2`.

|                       |                                                                 |
| --------------------- | --------------------------------------------------------------- |
| Operators             | `+ - * / ^`, parentheses, and numeric literals                  |
| Legs                  | up to four instruments                                          |
| Where it is evaluated | server-side, over the bucket intersection of the legs           |
| Which buckets exist   | only those every leg printed — a spread bar exists nowhere else |
| Volume                | `0` on every spread bar                                         |

An exact catalog match always wins over arithmetic: the slash pair `BTC/USD` is the symbol, never a
division. The same expression [resolves under symbol
details](/api-reference/market-data/get-symbol-details) as type `spread`, with no tick and no quote
surface, and it [streams](/api-reference/market-data/stream-live-bars) like any other instrument —
though any single leg's refusal refuses the whole spread.

## When history refuses

| Status | What it means                                                                                            |
| ------ | -------------------------------------------------------------------------------------------------------- |
| `400`  | A malformed timeframe token or parameter. The route fails closed rather than guessing at what you meant. |
| `429`  | Rate limited. The `Retry-After` header carries the wait.                                                 |
| `503`  | No feed serves this instrument.                                                                          |

On futures the `503` body carries a typed code, and the three are different problems:

| Code                       | What happened                                                                       | What to do                                       |
| -------------------------- | ----------------------------------------------------------------------------------- | ------------------------------------------------ |
| `feed_requires_connection` | Futures data streams from your own connected Rithmic account, and there is not one. | Connect an account.                              |
| `feed_capacity`            | The per-user session ceiling.                                                       | Retry shortly.                                   |
| `feed_displaced`           | Another application took over this login's market-data session.                     | It is a conflict at the venue, not a fault here. |

Anything else is `market_data_unavailable`.

## The pattern, in one line

Fetch the limits once, resolve the symbol once, backfill a window, then stream — and page back
with `countBack` until `noData` says stop. Everything else is presentation.

## Where to go deeper

* [Find symbols](/guides/find-symbols) — the limits, the catalog, and the tick and format a bar needs to render.
* [Stream live data](/guides/stream-live-data) — the snapshot-then-events contract that heals its own reconnects.
* [Streaming](/partner-platform/overview/streaming) — the reconnect contract in full.
* [Bring data via your venue](/guides/venue-data) — why a trader's own venue login is what serves these bars.
* [Rate limits](/partner-platform/overview/rate-limits) — what the `429` is counting.
