add Telegram alerts: qualified setups, S/R proximity, score drops, daily digest
Deploy / lint (push) Successful in 5s
Deploy / test (push) Successful in 35s
Deploy / deploy (push) Successful in 23s

Closes the action loop — instead of polling the dashboard, the platform pushes
actionable signals to Telegram. New hourly 'alerts' job dispatches four
toggleable triggers, deduped via a new alert_log table (cooldown-based for
qualified/S-R/digest, watermark-based for score deterioration). Admin → Settings
gains a Telegram panel (write-only bot token, chat ID, per-trigger toggles, Send
Test). Credentials follow DB > env precedence (TELEGRAM_BOT_TOKEN / _CHAT_ID).

Backend: alert_service + AlertLog model + migration 005, scheduler job, admin
endpoints/schema. Frontend: AlertSettings panel, hooks, api, types.

Deploy: run alembic upgrade (new alert_log table).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 19:42:18 +02:00
parent 9d0bef369f
commit 5d41ccac1c
17 changed files with 976 additions and 2 deletions
+2
View File
@@ -8,6 +8,7 @@ from app.models.sr_level import SRLevel
from app.models.trade_setup import TradeSetup
from app.models.watchlist import WatchlistEntry
from app.models.settings import SystemSetting, IngestionProgress
from app.models.alert import AlertLog
__all__ = [
"Ticker",
@@ -22,4 +23,5 @@ __all__ = [
"WatchlistEntry",
"SystemSetting",
"IngestionProgress",
"AlertLog",
]
+32
View File
@@ -0,0 +1,32 @@
from datetime import datetime
from sqlalchemy import DateTime, Float, Index, String
from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base
class AlertLog(Base):
"""Append-only log of alerts sent (and score watermarks).
Two uses, distinguished by ``alert_type``:
- notification dedup: a row records that ``dedup_key`` was alerted at
``created_at``; the dispatcher suppresses re-sending the same key within
a cooldown window.
- score watermark: rows of type ``score_watermark`` carry the last
observed composite in ``value``; the latest row per key is the baseline
for score-deterioration alerts.
"""
__tablename__ = "alert_log"
__table_args__ = (
Index("ix_alert_log_type_key_created", "alert_type", "dedup_key", "created_at"),
)
id: Mapped[int] = mapped_column(primary_key=True)
alert_type: Mapped[str] = mapped_column(String(30), nullable=False)
dedup_key: Mapped[str] = mapped_column(String(200), nullable=False)
value: Mapped[float | None] = mapped_column(Float, nullable=True)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=datetime.utcnow, nullable=False
)