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

# Data API

> The read-only HTTP API for settled trades and ended positions: which routes answer the last 48 hours, which keep the whole history, the page size, the request limit, and what a 429 means.

`https://data.rekt.trading` serves settled trades and ended positions, rebuilt by replaying each settlement
through the same engine the program runs. It is read-only and it needs no account. A web page on any
origin can call it: responses carry `Access-Control-Allow-Origin: *`, and a preflight (`OPTIONS`) is
answered. It sets no cookies and accepts no credentials. Start at `GET /v0/health`.

The program is the ground of truth and this API is a lagging mirror of it. It answers no live
question. Read live state from the chain through the [SDK](https://docs.rekt.money/sdk/quickstart.md).

## Routes

| Route | Returns | History |
| - | - | - |
| `GET /v0/health` | how fresh the archive is, and the limits that apply to your requests | now |
| `GET /v0/stats` | counts by market and by day, and the daily volume series | all time |
| `GET /v0/markets` | volume by market | all time |
| `GET /v0/trades` | settled trades, newest first. Filters: `owner`, `market`, `beforeSlot`, `limit`, `format=ndjson` | last 48 hours |
| `GET /v0/trades/{signature}` | one settled trade | last 48 hours |
| `GET /v0/minute/rounds` | Minute rounds. Filters: `owner`, `limit` | last 48 hours |
| `GET /v0/positions` | positions that have ended, settled or returned, with the phase each reached; a position that is still open is read from the chain. Filters: `owner`, `market`, `phase`, `signature`, `beforeSlot`, `limit` | last 48 hours |
| `GET /v0/capital` | the queue of unpaid wins in totals, how long the oldest has waited, and the closes made when a market had no price, by day | all time |
| `GET /v0/referral` | referral totals: the USDC referrers have claimed, how many referrers were paid, and how many traders are linked. Totals only | all time |

`owner` takes a wallet as base58 or as 64 hex characters. Any other value matches nothing: the page is
empty and `filters.owner` repeats what you sent.

## Limits

* **Per-transaction history is the last 48 hours.** `/v0/trades`, `/v0/minute/rounds` and
  `/v0/positions` return rows settled or ended in the last 48 hours. A round that is still open is dated by when it opened. A page that
  asks for older rows is empty. `/v0/trades/{signature}` answers `404` for a trade older than that,
  the same answer as for a signature it does not hold. `totalMatching`, `matched` and `nextBeforeSlot`
  count only the rows inside the window. The response states the window in its `window` field.
* **Pages hold at most 100 rows.** A larger `limit` is read as 100. Page with `beforeSlot`, using
  `nextBeforeSlot` from the previous page.
* **Requests are rate-limited.** `GET /v0/health` states the limit under `access`. A request over it
  gets `429` and a `Retry-After` header with the number of seconds to wait. Wait that long, then retry.
* **Days with fewer than 3 settlements are merged into the day after them** in `byDay`, `volumeByDay`
  and the day series of `/v0/capital`, and the response says so in `dayCells`. A merged day takes the label of
  the day it joined, and nothing is lost: the cells still sum to the total.
* **Poll the aggregates no more than once every 10 seconds.** `/v0/stats`, `/v0/markets`,
  `/v0/capital` and `/v0/referral` change at most that often and carry
  `Cache-Control: public, max-age=10, stale-while-revalidate=30`. The per-transaction routes carry
  `max-age=5`.
* **A request URL is at most 2,048 characters.** A longer one gets `414`.

`GET /v0/health` returns these figures for the caller that asked, under `access`. Read the limits from
there instead of copying them.

## History longer than 48 hours

* **Totals and trends:** `/v0/stats` returns `byDay` (settlements per day) and `volumeByDay` (per day:
  settlements, stake and notional). `/v0/markets` returns the all-time settlements, stake and notional
  per market. Both cover the whole archive.
* **One trader's older trades, or one older trade:** read them from the chain. `readTradeHistory` in
  the [SDK](https://docs.rekt.money/sdk/reference.md) scans a trader's closed trades from the program's own events.

## A request that is refused

| Status | Meaning | What to do |
| - | - | - |
| `400` | the request used a filter this API refuses | remove it. The filters are the ones in the table above. A parameter this API does not know is ignored |
| `400` | the path or the signature is malformed, or `phase` names an unknown or open phase | fix the request. Read an open position from the chain |
| `404` | no settled trade with this signature in the last 48 hours, or no such route | read it from the chain, or use the aggregates above |
| `405` | a method other than `GET`, `HEAD` or `OPTIONS` | use `GET` |
| `414` | the request URL is longer than 2,048 characters | shorten it |
| `429` | too many requests | wait `Retry-After` seconds |
| `500` | the server failed to answer | retry later |


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