Daily Python bot that mirrors US Congressional stock trades into an Alpaca paper trading account.
Members of the US Congress disclose their stock transactions under the STOCK Act, with the data aggregated and exposed by capitoltrades.com. I built this bot to ingest those filings on a daily schedule, filter them down to tradable US equities, and place sized market orders into a paper Alpaca account so I can study how a "follow-the-Congress" strategy actually performs without risking capital.
- Python 3.10+
- Alpaca Trading API (paper)
- Capitol Trades public BFF endpoint
requests,python-dotenv
- Daily ingestion of Congressional disclosures via the Capitol Trades JSON API with a configurable lookback window
- Equity-only filter — skips ETFs, mutual funds, treasuries, bonds, warrants, and other non-equity instruments by symbol and asset metadata
- Tradability check against Alpaca's
/assetsendpoint — drops symbols that aren'ttradable, active, andus_equity - Position sizing at 2% of portfolio equity per trade, with a configurable minimum disclosed-trade-size filter
- Side mapping — buys on disclosed purchases, sells on disclosed sales (only if a position exists), de-duped against open orders
- Market-on-day-open orders submitted with
time_in_force=day - Append-only logging with timestamps for every run, decision, and order outcome
- Python 3.10 or newer
- An Alpaca paper trading account with API keys
- (Optional) Windows Task Scheduler or cron for daily execution
git clone https://github.com/SayantoDutta/congress-trader.git
cd congress-trader
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS/Linux
pip install -r requirements.txtcopy .env.example .env # Windows
# cp .env.example .env # macOS/LinuxThen edit .env:
ALPACA_API_KEY=PK...
ALPACA_API_SECRET=...
ALPACA_ENDPOINT=https://paper-api.alpaca.markets/v2
One-shot run:
python congress_trader.pyDaily on Windows via Task Scheduler — point a daily trigger at:
powershell -ExecutionPolicy Bypass -File run_congress_trader.ps1The PowerShell wrapper appends both stdout and errors to congress_trader.log next to the script.
The pipeline runs end-to-end in a single script:
- Fetch the last N days of trades from
bff.capitoltrades.com/trades - Filter by minimum disclosed size, skip-keyword list, and asset class
- Resolve each ticker against Alpaca
/assets/<symbol>to confirm tradability - Size each order as
MAX_POS_PCT × portfolio_equity - Decide buy or sell based on disclosure direction and current Alpaca position
- Submit market orders, deduplicated against any open Alpaca orders for the same symbol
- Log every step to
congress_trader.log
Strategy parameters (lookback window, position sizing, minimum size, skip-keyword list) live as module-level constants near the top of congress_trader.py and can be tuned without touching the trade logic.
Active. Running daily into a paper account for performance study. Live trading is intentionally not supported — flip ALPACA_ENDPOINT only after additional risk controls are added.