# Pagination and filters

## Pages

Lists answer one page at a time:

```json
{ "items": [ … ], "total": 1342, "limit": 50, "offset": 100 }
```

| Parameter | Default | Range |
| --- | --- | --- |
| `limit` | 50 | 1–200 (the leaderboard: 1–100, default 25) |
| `offset` | 0 | 0–1,000,000 |

A value out of range is `400` (`"limit must be between 1 and 200"`); it is not clamped. `total` counts every item
that matches the filters within your [scope](/introduction#history-window), so `offset + items.length < total` means
there is another page.

```js
async function* allSignals(params) {
  for (let offset = 0; ; offset += 200) {
    const query = new URLSearchParams({ ...params, limit: "200", offset: String(offset) });
    const res = await fetch(`${base}/api/v1/customer/signals?${query}`, { headers: { Authorization: `Bearer ${key}` } });
    if (!res.ok) throw new Error(`${res.status}`);
    const page = await res.json();
    yield* page.items;
    if (offset + page.items.length >= page.total || page.items.length === 0) return;
  }
}
```

Each page is one metered request, so a full walk of a long list costs `total / 200` requests of your quota.

The inbox is the one list that pages by cursor instead: `GET /customer/notifications?before=<id>` with the
`nextBefore` of the previous answer (see [Watchlist, alerts and notifications](/alerts)).

## Signals: `GET /api/v1/customer/signals`

All filters combine with AND, and all stay inside your package's classes, history window and families: a filter can
narrow your scope, never widen it.

| Parameter | Values | Notes |
| --- | --- | --- |
| `q` | text | Ticker, filing id, issuer or company name contains |
| `classes` | `ACTION,WATCH,DROP` (comma list) | Intersected with your package's classes; an unknown class is 400 |
| `range` | `24h`, `7d`, `30d`, `90d` | Filed within; still cut to your history window |
| `from`, `to` | `YYYY-MM-DD` (UTC) | Filed on or after / on or before; `from` after `to` is 400 |
| `families` | `4,8-K,6-K,425,DEFA14A,13D,S-4,SC-TO,13E-3` | Comma list of form families |
| `minScore` | 0–100 | Score at least this; signals **without** a score are kept, add `classes=ACTION` to drop them |
| `minImpact` | 1–5 | The items' `impact` at least this |
| `tag` | a tag (repeatable, or a comma list) | Any of these [category tags](#category-tags); applied before paging, so `total` counts only tagged signals |
| `label` | `PENDING`, `ACTION`, `WATCH`, `DROP` | Realized market label |
| `issuerId` | CIK, up to 10 digits | One company |
| `sort` | `newest` (default), `oldest`, `score` | `score`: highest first, unscored last, then newest |

```bash
# ACTION 8-K and 425 filings of the last 7 days with a score of 80 or more, best first
curl -sS "$RISKPILOT_URL/api/v1/customer/signals?classes=ACTION&families=8-K,425&range=7d&minScore=80&sort=score" \
  -H "Authorization: Bearer $RISKPILOT_KEY"
```

Ties are ordered by filing id, so pages are stable while nothing new arrives.

### Category tags

Every signal carries `tags`, short category labels in the style of other filing feeds, from a fixed list:

`earnings`, `guidance`, `m-and-a`, `tender-offer`, `going-private`, `spac`, `leadership-change`, `insider`,
`insider-buy`, `insider-sell`, `beneficial-ownership`, `activist`, `proxy`, `proxy-fight`, `shareholder-vote`,
`offering`, `debt-financing`, `buyback`, `dividend`, `reverse-split`, `bankruptcy`, `restatement`, `delisting`,
`material-agreement`, `legal`, `cybersecurity`, `fda`, `clinical-trial`.

They are derived by fixed rules from data RiskPilot already stores, with no model call (method `tags_rules_v1`; the
full rule list is in the `Signal.tags` description of the [reference](/api)):

- **Form family:** Form 4 is `insider`, Schedule 13D `beneficial-ownership`, DEFA14A `proxy` (DFAN14A also
  `proxy-fight`), Schedule TO `tender-offer`, Schedule 13E-3 `going-private`, 425 and S-4 `m-and-a`.
- **8-K items:** 2.02 `earnings`, 5.02 `leadership-change`, 1.01/1.02 `material-agreement`, 1.03 `bankruptcy`, 1.05
  `cybersecurity`, 2.01 `m-and-a`, 2.03/2.04 `debt-financing`, 3.01 `delisting`, 3.02 `offering`, 4.02
  `restatement`, 5.07 `shareholder-vote`. Lists read an item from an explicit "Item N.NN" in the headline or summary;
  `GET /signals/{filingId}`, the webhook and the stream also read the filing's parsed item list, so a single signal
  can carry one item tag more than the same signal in a list.
- **Form 4 transaction codes:** P `insider-buy`, S `insider-sell` (and the summary's "open market purchase / sale").
- **Words** in the headline, summary or catalysts, matched case-insensitively at the start of a word, as a prefix
  (e.g. "merger", "acquisition", "dividend", "repurchase", "FDA", "Chapter 11", "reverse stock split").

A list item's `tags` and the `tag` filter use exactly the same rules (the filter runs in the database), so every item
a filter returns carries the tag. Word rules are simple on purpose: they can over-tag (a summary that mentions an
earnings release in passing gets `earnings`). An empty list means no rule matched.

```bash
# Insider buys and M&A, newest first
curl -sS "$RISKPILOT_URL/api/v1/customer/signals?tag=insider-buy&tag=m-and-a" -H "Authorization: Bearer $RISKPILOT_KEY"
```

The same filters, and the tags as `category` elements, are in the [RSS feed](/authentication#rss-feed-token).

## Companies: `GET /api/v1/customer/companies`

Only companies with at least one signal you may see are listed.

| Parameter | Values |
| --- | --- |
| `q` | Ticker, name or CIK contains |
| `sector` | One of the `sectors` the answer lists (SIC divisions) |
| `industry` | Industry (SIC description) contains |
| `cap` | `mega`, `large`, `mid` |
| `sort` | `marketCap` (default), `filings`, `recent`, `name` |

`GET /api/v1/customer/companies/{issuerId}` returns the profile, 30- and 90-day counts by class (`effectiveDays` says
when your history window is shorter than the period) and one page of the company's signals (`classes`, `limit`,
`offset`). It is `404` when you may see no signal of that company.

## Leaderboard: `GET /api/v1/customer/leaderboard`

Companies ranked by released ACTION signals in a window: `window` (`7d`, `30d` default, `90d`; cut to your history
window, see `effectiveDays`), `limit` (1–100, default 25), `family` (one form family). Ties share a rank.

## Keeping a copy in sync

New signals arrive at the top of `sort=newest`, so offsets shift while you page. For an incremental copy:

1. Prefer push: a [webhook](/webhooks) or the [stream](/stream) gives you each new signal once, at no quota cost.
2. If you poll, ask for the newest page (`sort=newest&limit=200`) and stop at the first `filingId` you already
   have. Poll no more often than your quota allows.
3. For a backfill, walk a fixed window with `from` and `to` (and `sort=oldest`), which does not shift.
4. The realized `label` changes later (from `PENDING` to a class). Refresh signals younger than your history window
   with `label=PENDING` now and then, or re-read a signal by id.

## Saved views

The portal saves filter sets per page (`customerSignals`, `customerCompanies`, `customerLeaderboard`) with
`GET/POST /customer/saved-views` and `DELETE /customer/saved-views/{id}`. An app can use the same routes to sync a
person's views across devices (session or live key; a named key gets `403 key_not_allowed`). A view's `query` is
flat: at most 20 fields of short strings, numbers, booleans or string lists. Saving the same name on the same page
replaces it.
