Files
k 5fb1d52026 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>
2026-05-25 00:52:56 +08:00

56 lines
2.2 KiB
Python

"""KOL module — Substack/Twitter post ingestion + AI analysis.
Standalone module, no FK into Trump posts/trades. First slice (B-tier):
- kol_posts: raw ingested posts from Substack/Twitter, keyed by URL
- (kol_holdings + kol_wallets reserved for A-tier in later migration)
Each post carries its own AI analysis inline (1:1, no separate table):
summary (one-sentence), tickers_json (list of {ticker, action,
conviction, quote}), model, analysis_version.
Revision ID: 017
Revises: 016
Create Date: 2026-05-23 00:00:00.000000
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "017"
down_revision: Union[str, None] = "016"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"kol_posts",
sa.Column("id", sa.Integer(), primary_key=True),
sa.Column("kol_handle", sa.String(64), nullable=False, index=True),
sa.Column("source", sa.String(16), nullable=False), # substack | twitter
sa.Column("external_id", sa.String(512), nullable=False), # canonical URL / tweet id
sa.Column("title", sa.String(512), nullable=True),
sa.Column("url", sa.String(512), nullable=False),
sa.Column("published_at", sa.DateTime(), nullable=False, index=True),
sa.Column("raw_text", sa.Text(), nullable=False),
sa.Column("content_hash", sa.String(64), nullable=False),
# ── Inline analysis (1:1, populated by extractor) ─────────────
sa.Column("summary", sa.Text(), nullable=True),
sa.Column("tickers_json", sa.Text(), nullable=True), # JSON list
sa.Column("analyzed_at", sa.DateTime(), nullable=True),
sa.Column("analysis_model", sa.String(64), nullable=True),
sa.Column("analysis_version", sa.String(16), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False,
server_default=sa.func.current_timestamp()),
sa.UniqueConstraint("source", "external_id", name="uq_kol_post_src_extid"),
)
def downgrade() -> None:
op.drop_table("kol_posts")