5fb1d52026
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>
79 lines
3.5 KiB
Python
79 lines
3.5 KiB
Python
"""KOL A-tier: on-chain wallet tracking + daily holdings snapshots.
|
|
|
|
Three new tables (standalone, no FK into Trump tables):
|
|
|
|
kol_wallets — curated KOL wallet addresses (one row per chain-addr pair)
|
|
kol_holdings_snapshots — daily portfolio snapshot per wallet (holdings_json)
|
|
kol_holding_changes — detected significant moves (new / closed / ±25%)
|
|
|
|
Source column distinguishes where the snapshot came from:
|
|
"arkham" — Arkham Intelligence API portfolio endpoint
|
|
"hl" — Hyperliquid public clearinghouseState (perps only)
|
|
"manual" — hand-entered for testing
|
|
|
|
Revision ID: 018
|
|
Revises: 017
|
|
Create Date: 2026-05-23
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
|
|
revision: str = "018"
|
|
down_revision: Union[str, None] = "017"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"kol_wallets",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("handle", sa.String(64), nullable=False, index=True),
|
|
sa.Column("chain", sa.String(16), nullable=False), # ethereum|solana|hl
|
|
sa.Column("address", sa.String(128), nullable=False),
|
|
sa.Column("label", sa.String(128), nullable=True), # e.g. "Arthur Hayes hot"
|
|
sa.Column("source_url", sa.String(256), nullable=True), # Arkham entity URL for reference
|
|
sa.Column("active", sa.Boolean(), nullable=False, server_default="1"),
|
|
sa.Column("added_at", sa.DateTime(), nullable=False,
|
|
server_default=sa.func.current_timestamp()),
|
|
sa.UniqueConstraint("chain", "address", name="uq_kol_wallet_chain_addr"),
|
|
)
|
|
|
|
op.create_table(
|
|
"kol_holdings_snapshots",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("wallet_id", sa.Integer(), sa.ForeignKey("kol_wallets.id"), nullable=False, index=True),
|
|
sa.Column("snapshot_date",sa.String(10), nullable=False), # YYYY-MM-DD UTC
|
|
sa.Column("holdings_json",sa.Text(), nullable=False), # [{ticker,amount,usd_value,chain}]
|
|
sa.Column("total_usd", sa.Float(), nullable=True),
|
|
sa.Column("source", sa.String(16), nullable=False), # arkham|hl|manual
|
|
sa.Column("created_at", sa.DateTime(), nullable=False,
|
|
server_default=sa.func.current_timestamp()),
|
|
sa.UniqueConstraint("wallet_id", "snapshot_date", name="uq_kol_snapshot_wallet_date"),
|
|
)
|
|
|
|
op.create_table(
|
|
"kol_holding_changes",
|
|
sa.Column("id", sa.Integer(), primary_key=True),
|
|
sa.Column("wallet_id", sa.Integer(), sa.ForeignKey("kol_wallets.id"), nullable=False, index=True),
|
|
sa.Column("detected_at", sa.DateTime(), nullable=False, index=True),
|
|
sa.Column("ticker", sa.String(32), nullable=False),
|
|
# new_position | closed | increased | decreased
|
|
sa.Column("change_type", sa.String(16), nullable=False),
|
|
sa.Column("usd_before", sa.Float(), nullable=True),
|
|
sa.Column("usd_after", sa.Float(), nullable=True),
|
|
sa.Column("pct_change", sa.Float(), nullable=True), # signed %
|
|
sa.Column("created_at", sa.DateTime(), nullable=False,
|
|
server_default=sa.func.current_timestamp()),
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_table("kol_holding_changes")
|
|
op.drop_table("kol_holdings_snapshots")
|
|
op.drop_table("kol_wallets")
|