# How to find insider buying clusters with the Form 4 API

Pull every open-market insider purchase for a window, group by company and keep the ones where three or more insiders bought. Python, 30 lines.

One insider buying is a data point. Three directors and the CFO buying the same stock in the same two weeks is a cluster, and clusters are the version of the insider signal that holds up in most studies. The Form 4 API has every open-market purchase with its dollar value, so finding them is one query and a group-by.

## Pull every purchase in the window

Transaction code `P` is an open-market or private purchase. Grants (`A`), option exercises (`M`) and tax withholding (`F`) are not buys and would drown the signal, so filter on `P` and on a dollar floor to skip token purchases.

### Which insiders bought more than $1 million of their own company's stock in the last 30 days?

Large open-market buys are the insider signal most studies find worth watching.

```shell
curl -X POST https://api.quantisnow.com/v1/insider-trades \
  -H "Authorization: Bearer $QUANTISNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "query": "formType:4 AND transactionCodes:P AND purchased.valueUsd:>1000000 AND filedAt:[2026-10-19 TO 2026-11-18]",
  "from": 0,
  "size": 5,
  "sort": [
    {
      "purchased.valueUsd": {
        "order": "desc"
      }
    }
  ]
}'
```

Response (real, first 2 of 93):

```json
{
  "total": {
    "value": 93,
    "relation": "eq"
  },
  "data": [
    {
      "accessionNo": "0001011438-26-000643",
      "formType": "4",
      "amendment": false,
      "restatesEarlier": false,
      "filedAt": "2026-11-03T16:35:59-05:00",
      "transactionDate": "2026-11-02",
      "issuer": {
        "cik": "0000789570",
        "name": "MGM Resorts International",
        "ticker": "MGM"
      },
      "reportingOwner": {
        "cik": "0001307631",
        "name": "Meister Keith A.",
        "officerTitle": null,
        "isDirector": true,
        "isOfficer": false,
        "isTenPercentOwner": false
      },
      "transactionCodes": [
        "P"
      ],
      "purchased": {
        "shares": 1745592,
        "valueUsd": 51740827.48
      },
      "sold": {
        "shares": 0,
        "valueUsd": 0
      },
      "sharesOwnedAfter": null,
      "rule10b51": false
    },
    {
      "accessionNo": "0001104659-26-121502",
      "formType": "4",
      "amendment": false,
      "restatesEarlier": false,
      "filedAt": "2026-11-02T17:45:33-05:00",
      "transactionDate": "2026-10-29",
      "issuer": {
        "cik": "0000084839",
        "name": "Rollins Inc",
        "ticker": "ROL"
      },
      "reportingOwner": {
        "cik": "0001212243",
        "name": "LOR INC",
        "officerTitle": null,
        "isDirector": false,
        "isOfficer": false,
        "isTenPercentOwner": true
      },
      "transactionCodes": [
        "P"
      ],
      "purchased": {
        "shares": 1444402,
        "valueUsd": 49956665.33
      },
      "sold": {
        "shares": 0,
        "valueUsd": 0
      },
      "sharesOwnedAfter": 146728468,
      "rule10b51": false
    }
  ]
}
```

## Group by company

```python
import os, requests
from collections import defaultdict

URL = "https://api.quantisnow.com/v1/insider-trades"
KEY = os.environ["QUANTISNOW_API_KEY"]
QUERY = "formType:4 AND transactionCodes:P AND purchased.valueUsd:>25000 AND filedAt:[2026-11-03 TO 2026-11-17]"

rows, start = [], 0
while True:
    page = requests.post(URL, headers={"Authorization": f"Bearer {KEY}"},
                         json={"query": QUERY, "from": start, "size": 50}).json()
    rows += page["data"]
    start += 50
    if start >= page["total"]["value"]:
        break

by_company = defaultdict(lambda: {"people": set(), "usd": 0})
for r in rows:
    c = by_company[r["issuer"]["ticker"]]
    c["people"].add(r["reportingOwner"]["cik"])
    c["usd"] += r["purchased"]["valueUsd"]

clusters = {t: c for t, c in by_company.items() if len(c["people"]) >= 3}
for ticker, c in sorted(clusters.items(), key=lambda kv: -kv[1]["usd"]):
    print(ticker, len(c["people"]), f"${c['usd']:,.0f}")
```

Count people by `reportingOwner.cik`, not by name. The same director files as "Smith John A" on one form and "SMITH JOHN" on the next; the CIK stays the same.

## Things that trip people up

- Amendments. A 4/A that repeats an earlier purchase comes back as its own record with `restatesEarlier: true`. Add `AND restatesEarlier:false` to count each trade once.
- Ten-percent owners. A fund that owns 10% files Form 4s too. Filter `reportingOwner.isTenPercentOwner:false` if you only want officers and directors.
- Windows over 10,000 rows. A two-week window of purchases never gets close, but if you widen it to a year of all transaction codes, split it by month. See [paging past 10,000 results](https://www.quantisnow.com/sec-api/guides/paginate-past-10000-results).


---

Get an API key: https://www.quantisnow.com/sec-api/keys (sign in and press Generate my key; the key arrives by email shortly and starts with 1,000 free calls).

All SEC API pages:

- [Overview](https://www.quantisnow.com/sec-api.md): SEC filings, insider trades, 13F holdings, financials and 8-K events through one query API, an MCP server and plain-English questions.
- [Get an API key](https://www.quantisnow.com/sec-api/keys): Generate a key; it arrives by email with 1,000 free calls.
- [Query syntax and limits](https://www.quantisnow.com/sec-api/query-syntax.md): Lucene query syntax, authentication, paging, sorting, rate limits and errors.
- [Playground](https://www.quantisnow.com/sec-api/playground): Run the example queries in the browser and see the real responses.
- [Filings search](https://www.quantisnow.com/sec-api/filings-search.md): Query 10-Ks, 10-Qs, 8-Ks, S-1s, Form D and every other EDGAR form with one Lucene query. Ticker, CIK, form type, filing time and links to the filing index, as JSON.
- [Insider trading](https://www.quantisnow.com/sec-api/insider-trading.md): Search insider purchases and sales from Form 4, initial holdings from Form 3 and planned sales from Form 144 by ticker, insider, role, dollar size and date.
- [13F holdings](https://www.quantisnow.com/sec-api/13f-holdings.md): Every 13F filer's positions by quarter, with shares, value and the change from the quarter before: new position, added, trimmed or sold out. Search by fund, CIK or ticker.
- [13D and 13G stakes](https://www.quantisnow.com/sec-api/beneficial-ownership.md): Search Schedule 13D activist stakes and 13G passive stakes by filer, company and date. Every filing above 5% ownership, as it is accepted.
- [Financial statements](https://www.quantisnow.com/sec-api/financial-statements.md): Quarterly and annual income statement, balance sheet and cash flow for every SEC filer, read from XBRL and normalized to the same field names. Search by ticker, fiscal year or any value.
- [8-K events](https://www.quantisnow.com/sec-api/8-k-events.md): Every Form 8-K with its item numbers: auditor changes (4.01), bankruptcies (1.03), delisting notices (3.01), executive changes (5.02), earnings (2.02) and the rest. Search by item, company and date.
- [News and press releases](https://www.quantisnow.com/sec-api/news-wire.md): Press releases from the major wires, FDA actions, analyst upgrades and downgrades and every SEC filing, tagged by ticker and category, in one searchable stream with a live websocket.
- [Plain-English questions](https://www.quantisnow.com/sec-api/natural-language.md): Ask a question in English; get back the query it became and the rows it found.
- [MCP server](https://www.quantisnow.com/sec-api/mcp.md): Search SEC data from Claude, ChatGPT and Cursor.
- [Find insider buying clusters with the Form 4 API](https://www.quantisnow.com/sec-api/guides/insider-buying-clusters.md): Pull every open-market insider purchase for a window, group by company and keep the ones where three or more insiders bought. Python, 30 lines.
- [Track activist investors with Schedule 13D filings](https://www.quantisnow.com/sec-api/guides/track-activist-13d-filings.md): Query new Schedule 13D filings, tell activists from passive 13G holders, and follow one fund across every company it files on.
- [See which funds bought or sold a stock from 13F filings](https://www.quantisnow.com/sec-api/guides/which-funds-bought-a-stock.md): Use the change field on 13F holdings to list new positions, increases and full exits in one stock for a quarter, without joining two quarters yourself.
- [Screen 8-K filings by item number: auditor changes, delistings and bankruptcies](https://www.quantisnow.com/sec-api/guides/8k-item-screener.md): What each 8-K item number means, which ones traders watch, and how to query one item across every company with the 8-K API.
- [Load SEC financial statements into pandas](https://www.quantisnow.com/sec-api/guides/financial-statements-pandas.md): Pull quarterly income statement, balance sheet and cash flow data from XBRL filings into a pandas DataFrame, and screen every filer on one metric.
- [Page past 10,000 results in a Lucene-style search API](https://www.quantisnow.com/sec-api/guides/paginate-past-10000-results.md): Why search APIs stop at 10,000 results per query and the date-window loop that gets every record anyway.
- [Search SEC filings from Claude, ChatGPT or Cursor with MCP](https://www.quantisnow.com/sec-api/guides/sec-filings-in-claude-mcp.md): Connect the Quantisnow MCP server to an AI assistant and ask about filings, insider trades, 13F holdings and financials in plain English.
- [SEC's free EDGAR APIs vs a filings search API: what each is for](https://www.quantisnow.com/sec-api/guides/sec-edgar-api-vs-data-sec-gov.md): What data.sec.gov, EDGAR full-text search and the bulk files give you for free, where they stop, and when a search API saves the work.
- [All guides](https://www.quantisnow.com/sec-api/guides.md): How-to guides with code and real responses.

Quantisnow is not affiliated with or endorsed by the U.S. Securities and Exchange Commission. EDGAR is the SEC's filing system; the filings themselves are public records.
