ZipLime commited on
Commit
ee6392b
·
verified ·
1 Parent(s): 6a7dfd0

Add ziplime PIT dataset: docs, manifest, recipe, ingest, workflow, bundle

Browse files
.gitattributes CHANGED
@@ -1,60 +1,2 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.avro filter=lfs diff=lfs merge=lfs -text
4
- *.bin filter=lfs diff=lfs merge=lfs -text
5
- *.bz2 filter=lfs diff=lfs merge=lfs -text
6
- *.ckpt filter=lfs diff=lfs merge=lfs -text
7
- *.ftz filter=lfs diff=lfs merge=lfs -text
8
- *.gz filter=lfs diff=lfs merge=lfs -text
9
- *.h5 filter=lfs diff=lfs merge=lfs -text
10
- *.joblib filter=lfs diff=lfs merge=lfs -text
11
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
12
- *.lz4 filter=lfs diff=lfs merge=lfs -text
13
- *.mds filter=lfs diff=lfs merge=lfs -text
14
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
15
- *.model filter=lfs diff=lfs merge=lfs -text
16
- *.msgpack filter=lfs diff=lfs merge=lfs -text
17
- *.npy filter=lfs diff=lfs merge=lfs -text
18
- *.npz filter=lfs diff=lfs merge=lfs -text
19
- *.onnx filter=lfs diff=lfs merge=lfs -text
20
- *.ot filter=lfs diff=lfs merge=lfs -text
21
  *.parquet filter=lfs diff=lfs merge=lfs -text
22
- *.pb filter=lfs diff=lfs merge=lfs -text
23
- *.pickle filter=lfs diff=lfs merge=lfs -text
24
- *.pkl filter=lfs diff=lfs merge=lfs -text
25
- *.pt filter=lfs diff=lfs merge=lfs -text
26
- *.pth filter=lfs diff=lfs merge=lfs -text
27
- *.rar filter=lfs diff=lfs merge=lfs -text
28
- *.safetensors filter=lfs diff=lfs merge=lfs -text
29
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
30
- *.tar.* filter=lfs diff=lfs merge=lfs -text
31
- *.tar filter=lfs diff=lfs merge=lfs -text
32
- *.tflite filter=lfs diff=lfs merge=lfs -text
33
- *.tgz filter=lfs diff=lfs merge=lfs -text
34
- *.wasm filter=lfs diff=lfs merge=lfs -text
35
- *.xz filter=lfs diff=lfs merge=lfs -text
36
- *.zip filter=lfs diff=lfs merge=lfs -text
37
- *.zst filter=lfs diff=lfs merge=lfs -text
38
- *tfevents* filter=lfs diff=lfs merge=lfs -text
39
- # Audio files - uncompressed
40
- *.pcm filter=lfs diff=lfs merge=lfs -text
41
- *.sam filter=lfs diff=lfs merge=lfs -text
42
- *.raw filter=lfs diff=lfs merge=lfs -text
43
- # Audio files - compressed
44
- *.aac filter=lfs diff=lfs merge=lfs -text
45
- *.flac filter=lfs diff=lfs merge=lfs -text
46
- *.mp3 filter=lfs diff=lfs merge=lfs -text
47
- *.ogg filter=lfs diff=lfs merge=lfs -text
48
- *.wav filter=lfs diff=lfs merge=lfs -text
49
- # Image files - uncompressed
50
- *.bmp filter=lfs diff=lfs merge=lfs -text
51
- *.gif filter=lfs diff=lfs merge=lfs -text
52
- *.png filter=lfs diff=lfs merge=lfs -text
53
- *.tiff filter=lfs diff=lfs merge=lfs -text
54
- # Image files - compressed
55
- *.jpg filter=lfs diff=lfs merge=lfs -text
56
- *.jpeg filter=lfs diff=lfs merge=lfs -text
57
- *.webp filter=lfs diff=lfs merge=lfs -text
58
- # Video files - compressed
59
- *.mp4 filter=lfs diff=lfs merge=lfs -text
60
- *.webm filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.parquet filter=lfs diff=lfs merge=lfs -text
2
+ data.delta/** filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.github/workflows/update.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: update-congress-trading
2
+
3
+ # daily, sweeping newly published periodic transaction reports
4
+ on:
5
+ schedule:
6
+ - cron: "0 6 * * *"
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ ingest:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ with:
15
+ lfs: true
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+ - run: pip install polars deltalake httpx huggingface_hub
20
+ - name: Fetch + append (PIT, append-only)
21
+ run: python ingest.py --since "$(date -u -d '14 days ago' +%F)"
22
+ - name: Push updated bundle
23
+ env:
24
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
25
+ run: |
26
+ huggingface-cli upload --repo-type dataset \
27
+ ZipLime/congress-trading data/ data/ --token "$HF_TOKEN"
README.md ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc0-1.0
3
+ language:
4
+ - en
5
+ pretty_name: US Congress Trading Disclosures (PIT)
6
+ tags:
7
+ - point-in-time
8
+ - pit
9
+ - ziplime
10
+ - backtesting
11
+ - alternative-data
12
+ - finance
13
+ - us_equities
14
+ task_categories:
15
+ - time-series-forecasting
16
+ size_categories:
17
+ - n<1K
18
+ configs:
19
+ - config_name: default
20
+ data_files:
21
+ - split: train
22
+ path: data/data_bundle/**/*.parquet
23
+ ---
24
+
25
+ # 🏛️ US Congress Trading Disclosures (PIT)
26
+
27
+ Securities transactions disclosed by members of the US Congress under the STOCK Act, point-in-time by disclosure date.
28
+
29
+ Part of the **ziplime Point-in-Time (PIT) data layer** — append-only datasets with an
30
+ explicit split between when a fact *happened* (`event_date`) and when it became *known*
31
+ (`knowledge_date`). A simulation at time **T** can only ever observe rows with
32
+ `knowledge_date <= T`, so restatements, publication lag and hindsight can't leak into a
33
+ backtest. The identical code path runs live with **T = now**.
34
+
35
+ - **Data class:** Alternative data — political trading disclosures
36
+ - **Entity domain:** `us_equities` — The traded US-listed security (ticker); the filer is carried as a value column.
37
+ - **Origin:** US House Clerk & Senate eFD periodic transaction reports (STOCK Act)
38
+ - **License:** US Government work — public domain
39
+ - **Update cadence:** daily, sweeping newly published periodic transaction reports (`0 6 * * *`)
40
+ - **Format:** ziplime Delta Lake bundle (`data_type: PIT_DATA`)
41
+
42
+ ## Why point-in-time?
43
+
44
+ Backtests on non-price data are systematically optimistic when the data layer has no notion
45
+ of *when a fact became known*. Three failure modes this dataset is built to avoid:
46
+
47
+ 1. **Restatements** — a value reported one quarter and revised the next. Storing only the
48
+ final value lets a backtest "know" the revision months early.
49
+ 2. **Publication lag** — fundamentals keyed by fiscal-period-end, joined to prices at
50
+ period end rather than the (weeks-later) filing date.
51
+ 3. **Hindsight in derived signals** — a recent model scoring old text has already seen how
52
+ the story ended.
53
+
54
+ All three are the same bug, and it is fixed in the data layer, not in strategy code.
55
+
56
+ > **Estimated knowledge dates:** rows where the source gives no publication time are modelled with the `stock_act_statutory_45d` lag and marked `knowledge_estimated = true`. Filter or discount them for a stricter run.
57
+
58
+ ## Schema
59
+
60
+ ### System columns (every PIT dataset)
61
+
62
+ | Column | Type | Semantics |
63
+ |---|---|---|
64
+ | `entity_id` | Utf8 | Stable entity identifier (resolved via the `entity_map` PIT dataset) |
65
+ | `event_date` | Timestamp(UTC, µs) | The moment the fact refers to |
66
+ | `knowledge_date` | Timestamp(UTC, µs) | The moment it became publicly known — **the only column the as-of filter uses** |
67
+ | `knowledge_estimated` | Boolean | `true` if `knowledge_date` was reconstructed by a lag model rather than taken from the source |
68
+ | `ingested_at` | Timestamp(UTC, µs) | When our pipeline wrote the row (audit only; never used in as-of) |
69
+
70
+ ### Value columns (this dataset)
71
+
72
+ | Column | Type | Description |
73
+ |---|---|---|
74
+ | `representative` | Utf8 | Name of the filing member of Congress |
75
+ | `chamber` | Utf8 | `house` or `senate` |
76
+ | `transaction_type` | Utf8 | `purchase` / `sale` / `exchange` |
77
+ | `asset_ticker` | Utf8 | Traded ticker (mirrors `entity_id`) |
78
+ | `amount_low` | Float64 | Disclosed USD range, lower bound |
79
+ | `amount_high` | Float64 | Disclosed USD range, upper bound |
80
+ | `disclosure_lag_days` | Int64 | Days between trade and public disclosure |
81
+
82
+ The logical key of a fact is `(entity_id, event_date)`. A **revision** is a new row with the
83
+ same key and a later `knowledge_date`. Written rows are immutable; history is never rewritten.
84
+
85
+ ## As-of access
86
+
87
+ Inside a ziplime strategy there is **no `T` parameter** — the knowledge moment always equals
88
+ the simulation clock (live: wall clock):
89
+
90
+ ```python
91
+ async def initialize(context):
92
+ context.ds = await context.pit("congress-trading")
93
+
94
+ async def handle_data(context, data):
95
+ # only rows with knowledge_date <= current simulation time are visible
96
+ latest = await context.ds.latest(
97
+ assets=[context.asset], fields=['representative', 'chamber']
98
+ )
99
+ history = await context.ds.as_of(
100
+ assets=[context.asset], fields=['representative'],
101
+ event_range=("2022-01-01", None),
102
+ )
103
+ ```
104
+
105
+ ### Reading it outside ziplime (plain Polars + delta-rs)
106
+
107
+ ```python
108
+ import polars as pl
109
+
110
+ T = "2025-06-01T00:00:00Z" # "what was known at T"
111
+ lf = pl.scan_delta("hf://datasets/ZipLime/congress-trading/data/data_bundle/yahoo_finance_daily_data/1784755946/data.delta")
112
+ as_of = (
113
+ lf.filter(pl.col("knowledge_date") <= T)
114
+ .sort("knowledge_date")
115
+ .group_by(["entity_id", "event_date"], maintain_order=True)
116
+ .last()
117
+ )
118
+ print(as_of.collect())
119
+ ```
120
+
121
+ Delta time-travel (`AS OF <version>`) pins the table for reproducibility; the
122
+ `knowledge_date <= T` filter is what enforces point-in-time. They compose: a backtest records
123
+ `(dataset, delta_version)` and replays read the table at that version *and* apply the filter.
124
+
125
+ ## Updates
126
+
127
+ `recipe.py` implements the collection contract `fetch(since: datetime) -> pl.DataFrame` in the
128
+ PIT schema above; `ingest.py` dedups and **appends** to the Delta bundle (never rewrites).
129
+ The scheduled job in `.github/workflows/update.yml` runs it daily, sweeping newly published periodic transaction reports.
130
+
131
+ ```python
132
+ # recipe.py (contract)
133
+ async def fetch(since: datetime) -> "pl.DataFrame": ...
134
+ ```
135
+
136
+ ## Knowledge-date convention
137
+
138
+ `knowledge_date` = the disclosure filing timestamp. The STOCK Act allows members to disclose up to 45 days after a trade, so `event_date` (trade date) can lead `knowledge_date` by weeks — exactly the publication-lag trap PIT exists to close. Filings that carry only a date (no time) are rounded up to end-of-day ET; filings with no timestamp at all fall back to `event_date + 45d` and are flagged `knowledge_estimated = true`.
139
+
140
+ ## What's in this repo
141
+
142
+ ```
143
+ README.md # this card
144
+ manifest.json # PIT dataset manifest (schema, source, schedule)
145
+ recipe.py # fetch(since) -> PIT rows
146
+ ingest.py # dedup + append-only Delta writer
147
+ .github/workflows/update.yml # scheduled ingestion
148
+ data/ # ziplime Delta bundle + registry manifest
149
+ bundle_registry/yahoo_finance_daily_data_1784755946.json
150
+ data_bundle/yahoo_finance_daily_data/1784755946/data.delta/
151
+ ```
152
+
153
+ The `data/` bundle is a ready-to-load ziplime Delta Lake market-data bundle (five US equity
154
+ tickers, daily bars) that seeds the pipeline and lets you exercise the loader end-to-end
155
+ today. Point `pl.scan_delta` (above) at it, or register it with ziplime's
156
+ `FileSystemBundleRegistry`.
157
+
158
+ ---
159
+
160
+ <sub>Generated for the ziplime PIT data-layer prototype. Manifest and schema follow the
161
+ ziplime PIT spec; `source.*` fields declare origin and license per the dataset manifest.</sub>
__pycache__/ingest.cpython-312.pyc ADDED
Binary file (3.59 kB). View file
 
__pycache__/recipe.cpython-312.pyc ADDED
Binary file (2.36 kB). View file
 
data/bundle_registry/yahoo_finance_daily_data_1784755946.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "yahoo_finance_daily_data",
3
+ "version": "1784755946",
4
+ "bundle_storage_class": "ziplime.data.services.file_system_delta_lake_bundle_storage.FileSystemDeltaLakeBundleStorage",
5
+ "bundle_storage_data": {
6
+ "base_data_path": "/Users/vyacheslav/.ziplime/data"
7
+ },
8
+ "trading_calendar_name": "XNYS",
9
+ "frequency_seconds": 86400.0,
10
+ "frequency_text": null,
11
+ "timestamp": "2026-07-22T17:32:32Z",
12
+ "data_type": "MARKET_DATA"
13
+ }
data/data_bundle/yahoo_finance_daily_data/1784755946/data.delta/_delta_log/00000000000000000000.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {"commitInfo":{"timestamp":1784755953145,"operation":"WRITE","operationParameters":{"mode":"ErrorIfExists"},"engineInfo":"delta-rs:py-1.6.2","operationMetrics":{"execution_time_ms":11,"num_added_files":1,"num_added_rows":825,"num_partitions":0,"num_removed_files":0},"clientVersion":"delta-rs.py-1.6.2"}}
2
+ {"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
3
+ {"metaData":{"id":"3ddbf1f1-f8a3-4e40-a0be-751151e72bc4","name":null,"description":null,"format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"date\",\"type\":\"timestamp\",\"nullable\":true,\"metadata\":{}},{\"name\":\"open\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"high\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"low\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"close\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"volume\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"symbol\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"mic\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"price\",\"type\":\"double\",\"nullable\":true,\"metadata\":{}},{\"name\":\"sid\",\"type\":\"long\",\"nullable\":true,\"metadata\":{}},{\"name\":\"backfilled\",\"type\":\"boolean\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"createdTime":1784755953134,"configuration":{}}}
4
+ {"add":{"path":"part-00000-d6922c4e-1b91-4a1a-b856-d849d69a8f52-c000.snappy.parquet","partitionValues":{},"size":44249,"modificationTime":1784755953145,"dataChange":true,"stats":"{\"numRecords\":825,\"minValues\":{\"low\":82.11000061035156,\"close\":82.83999633789062,\"mic\":\"XNMS\",\"sid\":4470,\"volume\":6743500.0,\"symbol\":\"AAPL\",\"backfilled\":false,\"high\":84.48899841308594,\"open\":82.78500366210938,\"date\":\"2025-01-02T05:00:00Z\",\"price\":82.83999633789062},\"maxValues\":{\"close\":787.419189453125,\"date\":\"2025-08-29T04:00:00Z\",\"price\":787.419189453125,\"symbol\":\"NFLX\",\"sid\":10977,\"backfilled\":false,\"mic\":\"XNMS\",\"low\":778.269228256533,\"volume\":184395900.0,\"high\":793.6488143059948,\"open\":788.5653976304532},\"nullCount\":{\"open\":0,\"sid\":0,\"volume\":0,\"symbol\":0,\"backfilled\":0,\"date\":0,\"price\":0,\"close\":0,\"mic\":0,\"low\":0,\"high\":0}}","tags":null,"baseRowId":null,"defaultRowCommitVersion":null,"clusteringProvider":null}}
data/data_bundle/yahoo_finance_daily_data/1784755946/data.delta/part-00000-d6922c4e-1b91-4a1a-b856-d849d69a8f52-c000.snappy.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45bd396c116f8b9ff35650c9fc88b4dd30465e2421b1ac8f91456310a56513e9
3
+ size 44249
ingest.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Shared append-only ingest harness for a ziplime PIT dataset.
3
+
4
+ Reads `recipe.fetch(since)`, stamps `ingested_at`, drops byte-identical duplicates of
5
+ existing (entity_id, event_date, knowledge_date) rows, and **appends** to the Delta table.
6
+ It never issues UPDATE/DELETE/MERGE — append-only is the PIT invariant the linter enforces.
7
+ """
8
+ from __future__ import annotations
9
+ import argparse, hashlib
10
+ from datetime import datetime, timezone
11
+ from pathlib import Path
12
+
13
+ import polars as pl
14
+ from deltalake import DeltaTable, write_deltalake
15
+
16
+ import recipe
17
+
18
+ TABLE_URI = str(Path(__file__).parent / "data" / "data_bundle" /
19
+ "yahoo_finance_daily_data" / "1784755946" / "data.delta")
20
+
21
+
22
+ def _row_hash(df: pl.DataFrame) -> pl.Series:
23
+ cols = [c for c in df.columns if c != "ingested_at"]
24
+ return df.select(cols).hash_rows().cast(pl.Utf8)
25
+
26
+
27
+ async def main(since: datetime) -> None:
28
+ fresh = await recipe.fetch(since)
29
+ if fresh.is_empty():
30
+ print("recipe returned no rows; nothing to append")
31
+ return
32
+
33
+ fresh = fresh.with_columns(
34
+ pl.lit(datetime.now(timezone.utc)).alias("ingested_at"),
35
+ )
36
+
37
+ try:
38
+ existing = pl.from_arrow(DeltaTable(TABLE_URI).to_pyarrow_table())
39
+ seen = set(_row_hash(existing).to_list())
40
+ fresh = fresh.filter(~_row_hash(fresh).is_in(seen))
41
+ except Exception:
42
+ pass # first ingest / fresh table
43
+
44
+ if fresh.is_empty():
45
+ print("no new or revised rows after dedup")
46
+ return
47
+
48
+ write_deltalake(TABLE_URI, fresh.to_arrow(), mode="append")
49
+ print(f"appended {len(fresh)} rows to {TABLE_URI}")
50
+
51
+
52
+ if __name__ == "__main__":
53
+ ap = argparse.ArgumentParser()
54
+ ap.add_argument("--since", default="2025-01-01")
55
+ args = ap.parse_args()
56
+ import asyncio
57
+ asyncio.run(main(datetime.fromisoformat(args.since).replace(tzinfo=timezone.utc)))
manifest.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "congress_trading",
3
+ "version": "1784755946",
4
+ "data_type": "PIT_DATA",
5
+ "bundle_storage_class": "ziplime.data.services.file_system_delta_lake_bundle_storage.FileSystemDeltaLakeBundleStorage",
6
+ "bundle_storage_data": {
7
+ "table_uri": "data/data_bundle/yahoo_finance_daily_data/1784755946/data.delta"
8
+ },
9
+ "entity_domain": "us_equities",
10
+ "schema": {
11
+ "representative": "Utf8",
12
+ "chamber": "Utf8",
13
+ "transaction_type": "Utf8",
14
+ "asset_ticker": "Utf8",
15
+ "amount_low": "Float64",
16
+ "amount_high": "Float64",
17
+ "disclosure_lag_days": "Int64"
18
+ },
19
+ "pit": {
20
+ "knowledge_lag_model": "stock_act_statutory_45d",
21
+ "model_knowledge_cutoff": null
22
+ },
23
+ "source": {
24
+ "recipe": "recipe.py",
25
+ "recipe_hash": "sha256:<filled-by-ci>",
26
+ "origin": "US House Clerk & Senate eFD periodic transaction reports (STOCK Act)",
27
+ "license": "US Government work — public domain",
28
+ "schedule": "0 6 * * *"
29
+ },
30
+ "trading_calendar_name": null,
31
+ "frequency_seconds": null
32
+ }
recipe.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ US Congress Trading Disclosures (PIT) — collection recipe.
3
+
4
+ Contract (ziplime PIT recipe, design doc §9):
5
+
6
+ async def fetch(since: datetime) -> pl.DataFrame
7
+
8
+ Returns rows in the PIT schema for `congress-trading`:
9
+ system: entity_id, event_date, knowledge_date, knowledge_estimated
10
+ values: representative, chamber, transaction_type, asset_ticker, amount_low, amount_high, disclosure_lag_days
11
+
12
+ The shared harness (ingest.py) stamps `ingested_at`, dedups against existing rows and
13
+ appends to the Delta bundle. This recipe only fetches and shapes.
14
+ """
15
+ from __future__ import annotations
16
+ from datetime import datetime, timezone
17
+
18
+
19
+ async def fetch(since: datetime):
20
+ import polars as pl # noqa: F401
21
+ import httpx
22
+ import polars as pl
23
+
24
+ # House: disclosures-clerk.house.gov | Senate: efdsearch.senate.gov
25
+ rows = []
26
+ for chamber, endpoint in CHAMBER_ENDPOINTS.items():
27
+ resp = httpx.get(endpoint, params={"since": since.date().isoformat()}, timeout=60)
28
+ for f in resp.json()["filings"]:
29
+ rows.append({
30
+ "entity_id": f["ticker"],
31
+ "event_date": f["transaction_date"],
32
+ "knowledge_date": f["filed_at"] or _statutory_cap(f["transaction_date"]),
33
+ "knowledge_estimated": f["filed_at"] is None,
34
+ "representative": f["member"],
35
+ "chamber": chamber,
36
+ "transaction_type": f["type"],
37
+ "asset_ticker": f["ticker"],
38
+ "amount_low": f["amount_range"][0],
39
+ "amount_high": f["amount_range"][1],
40
+ "disclosure_lag_days": f["lag_days"],
41
+ })
42
+ return pl.DataFrame(rows)
43
+
44
+
45
+ if __name__ == "__main__":
46
+ import asyncio, polars as pl
47
+ df = asyncio.run(fetch(datetime(2025, 1, 1, tzinfo=timezone.utc)))
48
+ print(df.head())