Back

Version 0

3/3/2025
import { email } from "https://esm.town/v/std/email?v=9";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";

/**
* Ya kya hai? (What is this?)
*
* This is a script that fetches recent stock trades by members of the US Congress.
* It retrieves the latest stock transactions reported by politicians,
* filters for trades made since the last run, and emails a summary.
*
* @param {Object} options - Contains the last time the script was run
* @returns {Promise<void>} Sends an email if new stock trades are found
*/
export async function fetchCongressTradeReports({ lastRunAt }) {
// Fetch the latest trade reports from Capitol Trades API
const res = await fetchJSON(
"https://bff.capitoltrades.com/trades?sortBy=-pubDate",
);

// Filter for stock trades reported since the last script run
const stockTradesReportedToday = res.data.filter((trade) => {
return (new Date(trade.pubDate) > lastRunAt
&& trade.asset.assetType === "stock");
});

// Format the trade details into a readable report
const reportings = stockTradesReportedToday
.map((trade) => {
return `
Politician: ${trade.politician.firstName + " " + trade.politician.lastName}
Party: ${trade.politician.party}
Asset: ${trade.asset.assetTicker}
Transaction Type: ${trade.txType}
Transaction Date: ${trade.txDate}
Estimated value: ~\$${trade.value}
`;
Updated: March 3, 2025