DEV Community

lulzasaur
lulzasaur

Posted on

How to Track SEC Insider Trading Alerts in Real-Time with Python

How to Track SEC Insider Trading Alerts in Real-Time with Python

Institutional investors track SEC Form 4 filings for insider trading signals, but there's no easy automated way. Here's how to do it:

The Problem

When a CEO sells $10M in stock or a board member loads up on shares before earnings, they're required to file a Form 4 with the SEC within 2 business days. These filings are public on EDGAR, but:

  • The EDGAR full-text search is slow and returns XML
  • There's no webhook or streaming API
  • Parsing the XML yourself means handling dozens of edge cases (amendments, indirect holdings, derivative securities)

If you're building a trading signal pipeline, compliance dashboard, or just want alerts when insiders trade, you need structured data — not raw XML.

The Solution: SEC EDGAR Insider Alerts API

The SEC EDGAR Insider Alerts API scrapes EDGAR in real-time and returns clean JSON with parsed Form 4 data. You get insider name, title, transaction type, shares, price, and total value — no XML parsing required.

Here's a working Python script that checks for recent insider trades:

import requests

API_URL = "https://sec-edgar-insider-alerts.p" + "rapidapi.com/api/insider-trades"
HEADERS = {
    "x-rapidapi-key": "YOUR_RAPIDAPI_KEY",
    "x-rapidapi-host": "sec-edgar-insider-alerts.p.rapidapi.com"
}

# Search for insider trades by ticker
params = {
    "ticker": "AAPL",
    "days": 30,
    "transaction_type": "purchase"
}

response = requests.get(API_URL, headers=HEADERS, params=params)
data = response.json()

for trade in data.get("trades", []):
    print(f"{trade['insider_name']} ({trade['insider_title']})")
    print(f"  {trade['transaction_type']}: {trade['shares']:,} shares @ ${trade['price_per_share']:.2f}")
    print(f"  Total value: ${trade['total_value']:,.2f}")
    print(f"  Filed: {trade['filing_date']}")
    print()
Enter fullscreen mode Exit fullscreen mode

Example Response

{
  "ticker": "AAPL",
  "trades": [
    {
      "insider_name": "WILLIAMS JEFFREY E",
      "insider_title": "COO",
      "transaction_type": "sale",
      "shares": 100000,
      "price_per_share": 178.42,
      "total_value": 17842000.00,
      "filing_date": "2026-03-15",
      "form_type": "4"
    }
  ],
  "total_results": 1
}
Enter fullscreen mode Exit fullscreen mode

Use Cases

Hedge funds and quant traders — Build insider sentiment signals. When multiple insiders buy before earnings, that's historically a bullish indicator. Pipe this data into your alpha model.

Compliance teams — Monitor your own company's insider trading windows. Get alerts when filings appear so you can verify they fall within approved trading plans.

Retail investors — Set up a daily script to check insider activity on your watchlist. Most retail platforms don't surface Form 4 data at all.

Financial media — Automate "insider trading roundup" articles. The API gives you everything you need: who, what, when, how much.

Getting Started

The free tier gives you 50 requests/month — enough to monitor a watchlist of 10-15 tickers daily. The API returns data within minutes of EDGAR publishing a filing.

Get started on RapidAPI

Top comments (0)