New SEC filings for a watchlist
Every 30 minutes, fetches the SEC's filing index for a few companies through the platform's open-data registry and sends a notice for each 8-K, 10-Q or 10-K filed since the last check, with a link to the filing. It checks the columns it needs against `describe()` at start, and treats each refusal code the way the guide says to.
Every 30 minutes, fetches the SEC's filing index for a few companies through the platform's open-data registry and sends a notice for each 8-K, 10-Q or 10-K filed since the last check, with a link to the filing. It checks the columns it needs against describe() at start, and treats each refusal code the way the guide says to.
Shows: Monitor, data.catalog(), data.describe(), data.fetch(..., symbol=), df.attrs["provenance"], open-data refusal codes (FETCH_FAILED, NOT_FOUND, AMBIGUOUS, CONTACT_REQUIRED), pandas, @on.schedule.
"""New SEC filings for a watchlist
Every 30 minutes, fetches the SEC's filing index for a few companies through
the platform's open-data registry and sends a notice for each 8-K, 10-Q or
10-K filed since the last check, with a link to the filing. It checks the
columns it needs against `describe()` at start, and treats each refusal code
the way the guide says to.
Shows: Monitor, data.catalog(), data.describe(), data.fetch(..., symbol=), df.attrs["provenance"], open-data refusal codes (FETCH_FAILED, NOT_FOUND, AMBIGUOUS, CONTACT_REQUIRED), pandas, @on.schedule.
"""
from datetime import date, timedelta
import while25
from while25 import Monitor, on
DATASET = "sec.company_filings"
WATCH = ["AAPL", "MSFT", "NVDA", "AMZN"]
FORMS = {"8-K", "10-Q", "10-K"}
NEEDS = ("filing_date", "report_type", "report_url")
def new_filings(df, since):
"""Rows of a wanted form filed on or after `since`, newest first."""
if df.empty:
return df
rows = df[df["report_type"].isin(FORMS) & (df["filing_date"] >= since)]
return rows.sort_values("filing_date", ascending=False)
class SecFilingsWatch(Monitor):
id = "sec_filings_watch"
label = "SEC filings watch"
def on_start(self, ctx):
ids = [d["id"] for d in while25.data.catalog("filings")]
if DATASET not in ids:
raise RuntimeError(f"{DATASET} is not in the open-data catalog: {ids}")
columns = {c["name"] for c in while25.data.describe(DATASET)["columns"]}
missing = [c for c in NEEDS if c not in columns]
if missing:
raise RuntimeError(f"{DATASET} no longer has {missing}")
self.since = {s: date.today() - timedelta(days=1) for s in WATCH}
@on.schedule(every="30m")
def check(self, ctx):
for sym in WATCH:
try:
df = while25.data.fetch(DATASET, symbol=sym)
except while25.While25Error as e:
if e.code == "FETCH_FAILED": # the source is busy: next pass
while25.log(f"{sym}: {e.message}", "warn")
continue
if e.code in ("NOT_FOUND", "AMBIGUOUS", "NOT_COVERED"):
while25.log(f"{sym}: {e.code}: {e.message}", "warn")
continue
raise # CONTACT_REQUIRED and the rest stop the run
for _, row in new_filings(df, self.since[sym]).iterrows():
while25.notify(f"{sym} filed a {row['report_type']} on {row['filing_date']}: "
f"{row['report_url']}", title="SEC filing", symbol=f"EQ:US:{sym}")
self.since[sym] = date.today()
src = df.attrs.get("provenance", {}).get("provider", "the source")
while25.log(f"{sym}: {len(df)} filings read from {src}")News alerts for a watchlist
Sends a notice for each live news article on AAPL, MSFT or NVDA whose title contains one of your keywords, and on start backfills the last day's articles to the console so nothing from the morning is missed. With no news vendor configured it says so once and keeps running.
Price alerts on symbols picked in the settings
Three symbol settings and a percent: whichever symbols are filled in, the monitor turns their prices on while it runs and sends a notice the first time each moves more than that percent from where it was when the monitor started. A symbol a setting names cannot go in a decorator, so its ticks are turned on with `subscribe(on_tick=...)`.