1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { email } from "https://esm.town/v/std/email?v=9";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export async function fetchCongressTradeReports({ lastRunAt }) {
const res = await fetchJSON(
"https://bff.capitoltrades.com/trades?sortBy=-pubDate",
);
const stockTradesReportedToday = res.data.filter((trade) => {
return (new Date(trade.pubDate) > lastRunAt &&
trade.asset.assetType === "stock");
});
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}
Esimated value: ~\$${trade.value}
`;
})
.join("\n\n");
if (stockTradesReportedToday.length)
await email({
text: reportings,
subject: "Congress Trade Report!",
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023