price-alerts
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrice Alerts (US markets)
价格提醒(美国市场)
Evaluates alert rules from the watchlist (see ) against fresh quotes and reports only new alerts.
Not financial advice. Never place, modify or cancel orders - even if an alert fires, even if a broker tool is connected, unless the user explicitly confirms that specific order in this conversation.
watchlist-managerscripts/npx skills addscripts/根据自选股列表(参见 )中的提醒规则对照最新行情进行评估,并且仅报告新增提醒。
不构成投资建议。绝不下单、修改或取消订单——即使提醒触发,即使连接了券商工具,除非用户在本次对话中明确确认该具体订单。
watchlist-managerscripts/SKILL.mdnpx skills addscripts/Run it
运行方式
bash
python3 scripts/watchlist.py init # copy examples/watchlist.json if missing
python3 scripts/quickstart.py # offline fixture demo (labeled, not live)
python3 scripts/alerts.py --watchlist watchlist.json --state .alert_state.json # text output
python3 scripts/alerts.py --format json # machine-readable
python3 scripts/alerts.py --force-session # evaluate on weekends / holidays too
python3 scripts/alerts.py --dry-run # don't update cooldown state
python3 scripts/alerts.py --notify # also deliver via WATCHLIST_NOTIFY sinks
python3 scripts/market_calendar.py # current ET sessionOutput: lines, or , or after the bell (last regular print; no needed). Weekends and full-day holidays stay silent () unless . Data errors go to stderr as (including / ). confirms delivery; sink failures are and must not abort the check. Never treat a notify sink as a broker.
ALERT <message>no new alertsmarket closed, showing last regular close--force-sessionmarket closed (weekend|holiday). Next session YYYY-MM-DD--force-sessionWARNearnings_erroriv_errorNOTIFY <sink>WARN notify …bash
python3 scripts/watchlist.py init # 如果缺失,则复制 examples/watchlist.json
python3 scripts/quickstart.py # 离线 fixture 演示(已标记,非实时行情)
python3 scripts/alerts.py --watchlist watchlist.json --state .alert_state.json # 文本输出
python3 scripts/alerts.py --format json # 机器可读格式
python3 scripts/alerts.py --force-session # 在周末/节假日也进行评估
python3 scripts/alerts.py --dry-run # 不更新冷却状态
python3 scripts/alerts.py --notify # 同时通过 WATCHLIST_NOTIFY 接收端投递
python3 scripts/market_calendar.py # 当前 ET 交易时段输出为 行,或 ,收盘后则为 (使用最近一次常规时段收盘价;无需 )。周末和全日节假日会保持静默(),除非使用 。数据错误通过 stderr 输出为 (包括 / )。 表示投递成功;接收端失败会显示为 ,且不得中止检查。绝不能将通知接收端视为券商。
ALERT <message>no new alertsmarket closed, showing last regular close--force-sessionmarket closed (weekend|holiday). Next session YYYY-MM-DD--force-sessionWARNearnings_erroriv_errorNOTIFY <sink>WARN notify …Alert types
提醒类型
| type | value | fires when | kind |
|---|---|---|---|
| price | last >= / <= value | level |
| price (default: ticker | long: last <= stop; short: last >= stop | level (implicit if |
| - | last crosses any | level (implicit if |
| % | last vs prior close (after hours: last regular close). A recovered session low does not fire | daily |
| % (default 2) | open vs prior close | daily |
| - | last beyond prior 252-session range | daily |
| % (default settings.near_52w_pct) | within value% of 52w extreme | daily-ish (level latch) |
| | SMA fast crosses slow on latest bar | daily |
| MA length (default 50) | last close crosses its SMA | daily |
| RSI level; optional | Wilder RSI on daily closes | level |
| IV percent | unofficial Yahoo ATM IV (nearest expiry); skip if missing/0 | level |
| multiple (default 2.0) | today's volume >= value x 20-day avg | daily |
| days (default 3) | next earnings date within N days | daily |
| % | | daily |
| % | opt-in session low/high vs prior close. Catches a −3% low that recovered into the close | daily |
| % | alias: expands to both | daily |
Any rule may set to override .
cooldown_minutessettings.cooldown_minutesDefault % checks use last print vs prior close ( / ). They do not look at the session high/low. If the user says “alert me if it drops 3% today” and they mean the print that traded through 3% even if it bounced, add (or ). Do not add those unless they ask — they are opt-in.
pct_change_*pct_moveintraday_low_pctintraday_extreme_pct| 类型 | 值 | 触发条件 | 类别 |
|---|---|---|---|
| 价格 | 最新价 >= / <= 设定值 | 阈值类 |
| 价格(默认取 ticker 的 | 多头:最新价 <= 止损价;空头:最新价 >= 止损价 | 阈值类(设置 |
| — | 最新价穿越任一 | 阈值类(设置 |
| % | 最新成交价与前收盘价相比(盘后:最近一次常规时段收盘价)。即使当日低点已经回升,也不会触发 | 每日类 |
| %(默认 2) | 开盘价与前收盘价相比 | 每日类 |
| — | 最新价突破此前 252 个交易时段的价格区间 | 每日类 |
| %(默认 | 距离 52 周极值在设定值%以内 | 近似每日(阈值锁存) |
| | 快速 SMA 在最新 K 线上穿/下穿慢速 SMA | 每日类 |
| MA 长度(默认 50) | 最新收盘价上穿/下穿其 SMA | 每日类 |
| RSI 水平;可选 | 基于每日收盘价计算 Wilder RSI | 阈值类 |
| IV 百分比 | 非官方 Yahoo ATM IV(最近到期日);缺失或为 0 时跳过 | 阈值类 |
| 倍数(默认 2.0) | 当日成交量 >= 设定值 x 20 日均量 | 每日类 |
| 天数(默认 3) | 下一次财报日期在 N 天内 | 每日类 |
| % | | 每日类 |
| % | 需显式启用的当日低点/高点与前收盘价比较。可捕捉盘中一度触及 −3% 后回升至收盘的情况 | 每日类 |
| % | 别名:展开为 | 每日类 |
任何规则都可设置 ,以覆盖 。
cooldown_minutessettings.cooldown_minutes默认百分比检查使用最新成交价与前收盘价比较( / ),不会查看当日最高价/最低价。如果用户说“今天跌 3% 时提醒我”,其意思是即使价格曾穿过 −3% 后又反弹,也要基于当时的成交价触发,请添加 (或 )。除非用户明确要求,否则不要添加;这些检查必须显式启用。
pct_change_*pct_moveintraday_low_pctintraday_extreme_pctAnti-spam rules (implemented in scripts/alerts.py
, state in .alert_state.json
)
scripts/alerts.py.alert_state.json防垃圾提醒规则(已在 scripts/alerts.py
中实现,状态保存在 .alert_state.json
)
scripts/alerts.py.alert_state.json- Level alerts latch: once fired they stay silent until price moves back through the level by (default 0.5%). A stock hovering at $240 never pings repeatedly.
rearm_pctrearms when ATM IV no longer breaches the threshold.iv_* - Daily-event alerts fire at most once per trading day per ticker/type.
- Cooldown (, default 240) applies to every re-fire.
cooldown_minutes - Cap of (default 20). Alerts past the cap are not written to state, so they can fire on the next run. If many fire, summarize ("7 alerts, 4 on TSLA") rather than dumping walls of text.
max_alerts_per_run - If the state file is missing or corrupt, start fresh but warn the user that duplicates are possible on this run.
- Each level is its own latched
targets[](T1 firing does not hide T2).target_hit
- 阈值类提醒会锁存:触发后会保持静默,直到价格回穿该价位并达到 (默认 0.5%)才会重新触发。一直在 $240 附近波动的股票不会反复提醒。
rearm_pct在 ATM IV 不再突破阈值时重新武装。iv_* - 每日事件类提醒每个交易日、每个 ticker/类型最多触发一次。
- 冷却时间(,默认 240)适用于每次重新触发。
cooldown_minutes - 每次运行最多触发 (默认 20)条提醒。超过上限的提醒不会写入状态,因此可以在下次运行时触发。如果大量提醒同时触发,应进行汇总(例如“7 条提醒,其中 4 条与 TSLA 有关”),而不是输出大量文本。
max_alerts_per_run - 如果状态文件缺失或损坏,则重新开始,但应警告用户本次运行可能出现重复提醒。
- 每个 价位都是独立的锁存式
targets[](T1 触发不会掩盖 T2)。target_hit
Market hours (America/New_York, handled by scripts/market_calendar.py
)
scripts/market_calendar.py交易时段(America/New_York,由 scripts/market_calendar.py
处理)
scripts/market_calendar.py- Pre-market 04:00-09:30, regular 09:30-16:00, after-hours 16:00-20:00 ET; early-close days (day after Thanksgiving, Christmas Eve, July 3 when a weekday) close 13:00 with after-hours to 17:00.
- NYSE holidays: New Year's (not observed when Saturday), MLK, Presidents', Good Friday, Memorial, Juneteenth, Independence, Labor, Thanksgiving, Christmas (Sat -> Fri, Sun -> Mon). Unscheduled closures: bundled ,
data/holidays_overrides.json/NYSE_EXTRA_CLOSURES, and (with Alpaca keys) weekdays missing from the official calendar. Mention it if quotes look stale on a weekday the calendar thinks is open.settings.extra_closures - controls when extended-hours quotes are treated as live. Default
settings.sessions. After the bell (or pre-open / overnight) on a trading day, the script still evaluates the last regular close and labels["regular"]— you do not needlast_close. Add--force-session/"pre"only if you want to treat extended-hours prints as the live session. Those quotes are thinner and free sources may lag."after" - Always state times in ET (add the user's local time if known, e.g. "10:05 ET / 9:05 CT").
- 盘前交易 04:00-09:30,常规交易 09:30-16:00,盘后交易 16:00-20:00 ET;提前收盘日(感恩节次日、平安夜、7 月 3 日且为工作日时)在 13:00 收盘,盘后交易持续到 17:00。
- NYSE 节假日:元旦(逢周六不观察)、MLK、总统日、耶稣受难日、阵亡将士纪念日、六月节、独立日、劳工节、感恩节、圣诞节(周六 -> 周五,周日 -> 周一)。非计划休市:内置 、
data/holidays_overrides.json/NYSE_EXTRA_CLOSURES,以及配置 Alpaca 密钥后对官方日历中缺失交易日的补充。如果日历认定某工作日开市,但行情看起来已过期,应说明这一点。settings.extra_closures - 控制何时将延长交易时段行情视为实时行情。默认为
settings.sessions。在交易日收盘后(或开盘前/隔夜期间),脚本仍会使用最近一次常规时段收盘价进行评估,并将其标记为["regular"]——无需last_close。仅当希望将盘前/盘后成交视为当前交易时段时,才添加--force-session/"pre"。这类行情流动性较低,免费数据源可能存在延迟。"after" - 始终使用 ET 标注时间(如果已知用户所在时区,也应添加本地时间,例如“10:05 ET / 9:05 CT”)。
Data sources (scripts/quotes.py
, auto-fallback in this order)
scripts/quotes.py数据源(scripts/quotes.py
,按以下顺序自动回退)
scripts/quotes.py- path, if given (tests/demos only).
--fixture - Alpaca snapshot + daily bars, if and
ALPACA_API_KEY_IDare set (official US feed).ALPACA_API_SECRET_KEY - if installed (
yfinance).pip install yfinance - Yahoo public chart API (stdlib, unofficial, best-effort): , then
query1.finance.yahoo.com.query2isprev_closeor the prior aligned daily bar — after ~20:00 ET a today-row withpreviousCloseis dropped, not treated as yesterday.close: None - Finnhub quote + candles, if is set.
FINNHUB_API_KEY - Alpha Vantage daily, if is set.
ALPHAVANTAGE_API_KEY
Force one with or . HTTP 429/5xx are retried; failures are tagged s (provider, HTTP status, hint). Free data can be delayed ~15 min; say so when precision matters.
--providerWATCHLIST_PROVIDERQuoteErrorEarnings dates are filled after the quote, first hit: existing field (yfinance/fixture) → Yahoo (cookie + crumb) → Yahoo quote HTML → Nasdaq analyst (free, no key) → Finnhub / Alpha Vantage if keyed. says which layer won; if none do, prints a WARN.
calendarEventsearnings-dateearnings_sourceearnings_errorStale quotes: / / (default 900). During the regular session, warn if is older than that. disables.
--stale-afterWATCHLIST_STALE_AFTERsettings.stale_after_secondsas_of0ATM IV: only fetched for tickers with /. Unofficial Yahoo options chain (same crumb), then yfinance if installed. Nearest expiration, ATM call/put average as percent. Not IV rank. Failures set and print a WARN. to inspect.
iv_aboveiv_belowiv_errorpython3 scripts/quotes.py AAPL --ivNotify (optional): and/or . See README for env vars. Do not notify on empty/skipped/dry-run. Delivery errors stay warnings.
WATCHLIST_NOTIFY=ntfy,slack,webhook,desktop,file--notifyKnown limits: unscheduled closures live in (incomplete) plus env/settings plus an optional Alpaca official calendar overlay (day-cached). Yahoo endpoints are unofficial. See .
data/holidays_overrides.jsondocs/LIMITATIONS.mdMCP option: if an MCP server (alpacahq/alpaca-mcp-server) or MCP (atilaahmettaner/tradingview-mcp) is connected, you may use it for quotes/indicators instead of the scripts, then apply the exact same rules and anti-spam logic (read/write in the same format). Use broker MCPs for read-only calls only.
alpacatradingview.alert_state.json- 如果提供了 路径,则使用该路径(仅用于测试/演示)。
--fixture - 如果同时设置 和
ALPACA_API_KEY_ID,则使用 Alpaca snapshot 和日线数据(美国官方行情源)。ALPACA_API_SECRET_KEY - 如果已安装 ,则使用
yfinance(yfinance)。pip install yfinance - Yahoo 公共图表 API(仅使用标准库,非官方,尽力而为):先访问 ,然后访问
query1.finance.yahoo.com。query2取prev_close或按日期对齐的上一根日线;在 ET 时间约 20:00 之后,如果今日行包含previousClose,则将其丢弃,而不是视为昨日数据。close: None - 如果设置了 ,则使用 Finnhub 报价和 K 线数据。
FINNHUB_API_KEY - 如果设置了 ,则使用 Alpha Vantage 日线数据。
ALPHAVANTAGE_API_KEY
使用 或 可强制指定某个数据源。HTTP 429/5xx 会重试;失败会标记为 (数据源、HTTP 状态、提示)。免费数据可能延迟约 15 分钟;对精度有要求时应说明这一点。
--providerWATCHLIST_PROVIDERQuoteError财报日期在获取行情后填充,按以下顺序采用第一个可用来源:现有字段(yfinance/fixture)→ Yahoo (cookie + crumb)→ Yahoo 报价 HTML → Nasdaq 分析师 (免费、无需密钥)→ 已配置密钥时使用 Finnhub / Alpha Vantage。 表明最终采用的数据层;如果全部失败, 会输出 WARN。
calendarEventsearnings-dateearnings_sourceearnings_error**过期行情:**可通过 / / 配置(默认 900)。常规交易时段内,如果 早于该时间,则发出警告。 表示禁用。
--stale-afterWATCHLIST_STALE_AFTERsettings.stale_after_secondsas_of0**ATM IV:**仅为配置了 / 的 ticker 获取。使用非官方 Yahoo 期权链(同一 crumb),然后回退到已安装的 yfinance。选择最近到期日,以 ATM call/put 的平均值表示百分比。不是 IV rank。失败时设置 并输出 WARN。可通过 检查。
iv_aboveiv_belowiv_errorpython3 scripts/quotes.py AAPL --iv**通知(可选):**可通过 和/或 启用。环境变量参见 README。没有提醒、提醒被跳过或处于 dry-run 状态时不得发送通知。投递错误仅作为警告处理。
WATCHLIST_NOTIFY=ntfy,slack,webhook,desktop,file--notify**已知限制:**非计划休市信息来自 (并不完整)、环境变量/设置以及可选的 Alpaca 官方日历叠加层(按日缓存)。Yahoo 端点均为非官方接口。参见 。
data/holidays_overrides.jsondocs/LIMITATIONS.mdMCP 选项:如果连接了 MCP 服务器(alpacahq/alpaca-mcp-server)或 MCP(atilaahmettaner/tradingview-mcp),可以使用它们获取行情/指标来代替脚本,然后应用完全相同的规则和防垃圾提醒逻辑(以相同格式读写 )。broker MCP 仅可用于只读调用。
alpacatradingview.alert_state.jsonReporting format
报告格式
🔔 3 new alerts (10:05 ET, regular session, data: yahoo, ~15m delayed)
- AAPL $241.50 is above $240.00 (thesis: services margin; stop $210, T1 $250)
- TSLA down -6.0% today, gapped down -5.0%, volume 3.0x avg
- TSLA reports earnings in 1 day (2026-10-16)Group by ticker, include the stored thesis/stop/target for context, no recommendations. If no alerts: one short line, or stay silent when running on a heartbeat (see ).
HEARTBEAT.md🔔 3 条新提醒(10:05 ET,常规交易时段,数据源:yahoo,约延迟 15 分钟)
- AAPL $241.50 已高于 $240.00(投资逻辑:服务业务利润率;止损 $210,T1 $250)
- TSLA 今天下跌 -6.0%,向下跳空 -5.0%,成交量为均值的 3.0 倍
- TSLA 将在 1 天后发布财报(2026-10-16)按 ticker 分组,附上已存储的投资逻辑、止损和目标价以便理解上下文,不要给出建议。如果没有提醒:输出一行简短信息;在运行心跳检查时则保持静默(参见 )。
HEARTBEAT.mdCreating alerts from chat
从对话中创建提醒
"Alert me if AAPL drops below 200" -> (add the ticker first if missing). Confirm the rule back in plain English.
python scripts/watchlist.py update AAPL --alert price_below:200 --append“如果 AAPL 跌到 200 美元以下就提醒我” -> (如果列表中还没有该 ticker,请先添加)。用简单直白的话向用户复述规则并确认。
python scripts/watchlist.py update AAPL --alert price_below:200 --append