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:
k
2026-05-25 00:52:56 +08:00
parent b941223c88
commit 5fb1d52026
81 changed files with 13251 additions and 158 deletions
+48
View File
@@ -0,0 +1,48 @@
"""kol_divergence table — talks-vs-trades cross-signal
Revision ID: 019
Revises: 018
Create Date: 2026-05-23
"""
from alembic import op
import sqlalchemy as sa
revision = "019"
down_revision = "018"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"kol_divergence",
sa.Column("id", sa.Integer, primary_key=True),
# Which KOL + asset
sa.Column("handle", sa.String(64), nullable=False, index=True),
sa.Column("ticker", sa.String(32), nullable=False),
# Content side (B-tier)
sa.Column("post_id", sa.Integer, sa.ForeignKey("kol_posts.id"), nullable=False),
sa.Column("post_action", sa.String(16), nullable=False), # buy|sell|bullish|bearish
sa.Column("post_conviction", sa.Float, nullable=True),
sa.Column("post_at", sa.DateTime, nullable=False), # post published_at
# On-chain side (A-tier)
sa.Column("change_id", sa.Integer, sa.ForeignKey("kol_holding_changes.id"), nullable=False),
sa.Column("onchain_action", sa.String(16), nullable=False), # new_position|increased|decreased|closed
sa.Column("usd_before", sa.Float, nullable=True),
sa.Column("usd_after", sa.Float, nullable=True),
sa.Column("onchain_at", sa.DateTime, nullable=False),
# Classification
sa.Column("signal_type", sa.String(16), nullable=False), # divergence | alignment
sa.Column("direction", sa.String(8), nullable=True), # long | short (net conclusion)
sa.Column("days_apart", sa.Float, nullable=True), # abs days between post and onchain event
sa.Column("created_at", sa.DateTime, nullable=False, server_default=sa.func.now()),
# Unique: one row per (post, change) pair so re-runs are idempotent
sa.UniqueConstraint("post_id", "change_id", name="uq_kol_divergence_pair"),
)
op.create_index("ix_kol_divergence_handle_ticker", "kol_divergence", ["handle", "ticker"])
op.create_index("ix_kol_divergence_signal_type", "kol_divergence", ["signal_type"])
op.create_index("ix_kol_divergence_created_at", "kol_divergence", ["created_at"])
def downgrade() -> None:
op.drop_table("kol_divergence")