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>
47 lines
2.3 KiB
Python
47 lines
2.3 KiB
Python
"""Two-system separation + frozen per-trade exit profile.
|
|
|
|
subscriptions:
|
|
- sys2_budget_pct : daily-budget slice for System 2 (default 0.7)
|
|
- sys2_cb_tripped_at/reason : independent System-2 circuit breaker
|
|
|
|
bot_trades:
|
|
- eff_* : the exit profile FROZEN at open. Recovery rehydrates from these
|
|
instead of the (mutable) Subscription, so a 90-day reversal
|
|
isn't silently rewritten to the user's Trump stop on restart.
|
|
"""
|
|
from typing import Sequence, Union
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "009"
|
|
down_revision: Union[str, None] = "008"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
with op.batch_alter_table("subscriptions") as b:
|
|
b.add_column(sa.Column("sys2_budget_pct", sa.Float(), nullable=False, server_default="0.7"))
|
|
b.add_column(sa.Column("sys2_cb_tripped_at", sa.DateTime(), nullable=True))
|
|
b.add_column(sa.Column("sys2_cb_reason", sa.String(32), nullable=True))
|
|
with op.batch_alter_table("bot_trades") as b:
|
|
b.add_column(sa.Column("eff_take_profit_pct", sa.Float(), nullable=True))
|
|
b.add_column(sa.Column("eff_stop_loss_pct", sa.Float(), nullable=True))
|
|
b.add_column(sa.Column("eff_trailing_stop_pct", sa.Float(), nullable=True))
|
|
b.add_column(sa.Column("eff_trailing_activate_pct", sa.Float(), nullable=True))
|
|
b.add_column(sa.Column("eff_max_hold_hours", sa.Integer(), nullable=True))
|
|
b.add_column(sa.Column("eff_invalidation", sa.String(24), nullable=True))
|
|
b.add_column(sa.Column("eff_invalidation_price", sa.Float(), nullable=True))
|
|
b.add_column(sa.Column("eff_min_hold_until_ts", sa.Float(), nullable=True))
|
|
|
|
|
|
def downgrade() -> None:
|
|
with op.batch_alter_table("bot_trades") as b:
|
|
for c in ("eff_min_hold_until_ts", "eff_invalidation_price", "eff_invalidation", "eff_max_hold_hours",
|
|
"eff_trailing_activate_pct", "eff_trailing_stop_pct",
|
|
"eff_stop_loss_pct", "eff_take_profit_pct"):
|
|
b.drop_column(c)
|
|
with op.batch_alter_table("subscriptions") as b:
|
|
for c in ("sys2_cb_reason", "sys2_cb_tripped_at", "sys2_budget_pct"):
|
|
b.drop_column(c)
|