""" SEC Form 4 Insider Transactions (PIT) — collection recipe. Contract (ziplime PIT recipe, design doc §9): async def fetch(since: datetime) -> pl.DataFrame Returns rows in the PIT schema for `insider-transactions`: system: entity_id, event_date, knowledge_date, knowledge_estimated values: insider_name, insider_role, transaction_code, shares, price_per_share, shares_owned_after The shared harness (ingest.py) stamps `ingested_at`, dedups against existing rows and appends to the Delta bundle. This recipe only fetches and shapes. """ from __future__ import annotations from datetime import datetime, timezone async def fetch(since: datetime): import polars as pl # noqa: F401 import httpx import polars as pl rows = [] for f4 in _stream_form4(since): # EDGAR full-text index, form=4 doc = httpx.get(f4["xml_url"], headers=SEC_UA, timeout=60).text for txn in _parse_form4(doc): rows.append({ "entity_id": f4["issuer_ticker"], "event_date": txn["transaction_date"], "knowledge_date": f4["accepted_at"], "knowledge_estimated": False, "insider_name": f4["reporter"], "insider_role": txn["role"], "transaction_code": txn["code"], "shares": txn["shares"], "price_per_share": txn["price"], "shares_owned_after": txn["owned_after"], }) return pl.DataFrame(rows) if __name__ == "__main__": import asyncio, polars as pl df = asyncio.run(fetch(datetime(2025, 1, 1, tzinfo=timezone.utc))) print(df.head())