Pre-launch hardening: KOL module, Telegram, scanners, WS resilience
Big-picture changes since b941223:
KOL pipeline (new) — Substack/podcast/blog RSS → AI ticker extraction →
on-chain wallet diff → talks-vs-trades divergence detection. Daily polls,
19 feeds, divergence emits Post + Telegram fan-out.
Telegram push (new) — walletless free tier + wallet-linked Pro upgrade,
in-bot preference commands (/trump /btc /funding /kol /conf /quiet),
signed-envelope API for dashboard. Disconnect-wallet keeps free
subscription.
BTC funding-rate reversal scanner (new) — hourly cron, 30d cumulative
funding threshold + mean-revert + 7d price confirm, emits via
/api/signals/ingest. BTC bottom-reversal scanner promoted to System 2.
WS broadcast rewrite — per-client send timeout + parallel fan-out
(asyncio.gather). Fixes "Binance WS no close frame" reconnect storms +
APScheduler 11-min job misses, both caused by one slow client stalling
the kline loop.
Error visibility — three silent-error sites (trumpstruth/truth_social
fetchers, funding_reversal scanner) now include exception type name so
httpx ConnectError-style empty-message errors stop logging blank lines.
Telegram bot loop now classifies ReadTimeout vs network vs unknown +
logger.exception for the unknown bucket.
Security hygiene — trumpsignal.db untracked from git (held subscriber
wallets + encrypted HL keys + 22 bot trades); .gitignore now blocks
*.db/.next/backups. CORS only allows FRONTEND_URL in production.
New ops scripts —
- scripts/preflight.py: env/DB/Telegram/AI auth verification gate
- scripts/backup_db.sh: cron-friendly daily DB backup (SQLite + Postgres)
- scripts/seed_kol_wallets.py: idempotent KOL on-chain wallet seeder
15 new Alembic migrations (007-021) covering convex strategy fields,
phase-1 safety, two-system frozen exits, invalidation prices, dynamic
SYS2 leverage, staged de-risk + pyramiding, peak gain tracking, risk
mode, auto-trade + grow flags, KOL module, KOL on-chain, KOL divergence,
Telegram bindings + walletless.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""telegram_bindings — wallet ↔ Telegram chat_id mapping with per-source prefs.
|
||||
|
||||
Revision ID: 020
|
||||
Revises: 019
|
||||
Create Date: 2026-05-24
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = "020"
|
||||
down_revision = "019"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"telegram_bindings",
|
||||
sa.Column("id", sa.Integer, primary_key=True),
|
||||
sa.Column("wallet_address", sa.String(64), nullable=False, unique=True, index=True),
|
||||
# Telegram chat_id is an int64 in practice; store as BigInteger to be safe.
|
||||
sa.Column("chat_id", sa.BigInteger, nullable=False, unique=True, index=True),
|
||||
sa.Column("tg_username", sa.String(64), nullable=True), # display only
|
||||
sa.Column("bound_at", sa.DateTime, nullable=False, server_default=sa.func.now()),
|
||||
# Master switch
|
||||
sa.Column("alerts_enabled", sa.Boolean, nullable=False, server_default=sa.true()),
|
||||
# Per-source toggles. KOL divergence is noisier so default-off.
|
||||
sa.Column("alert_trump", sa.Boolean, nullable=False, server_default=sa.true()),
|
||||
sa.Column("alert_btc_bottom", sa.Boolean, nullable=False, server_default=sa.true()),
|
||||
sa.Column("alert_funding", sa.Boolean, nullable=False, server_default=sa.true()),
|
||||
sa.Column("alert_kol_divergence", sa.Boolean, nullable=False, server_default=sa.false()),
|
||||
# Quality floor — don't ping for low-confidence Trump posts.
|
||||
sa.Column("min_confidence", sa.Integer, nullable=False, server_default="70"),
|
||||
# Quiet hours (UTC). 0..23. Both null = always on. If start<end, mute
|
||||
# [start, end); if start>end, mute window wraps midnight.
|
||||
sa.Column("mute_from_hour", sa.Integer, nullable=True),
|
||||
sa.Column("mute_until_hour", sa.Integer, nullable=True),
|
||||
# Audit
|
||||
sa.Column("last_alert_at", sa.DateTime, nullable=True),
|
||||
sa.Column("total_alerts_sent", sa.Integer, nullable=False, server_default="0"),
|
||||
sa.Column("total_alerts_failed", sa.Integer, nullable=False, server_default="0"),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("telegram_bindings")
|
||||
Reference in New Issue
Block a user