Three pre-launch audit findings:
launch_seed.py — destructive cleanup is now OPT-IN
Previously `launch_seed.py --yes` truncated KOL history (divergence /
holdings / posts older than 30d) by default — an accidental run erased
unrecoverable data, and abort_if_live_user_state() only guards on
subscriptions/bindings, not KOL history. Now nothing is deleted unless
--wipe is passed; the safe path is --seed-only (pure fetch). Bare/--yes
without --wipe refuses and prints guidance.
/api/health/deep — monitor the price feeds, not just scrapers
The deep healthcheck only watched the (redundant) Trump scrapers + DB, so a
dead Binance/HL price feed — which silently stops ALL tp_sl_monitor stop-loss
/ take-profit firing on live trades — left health green. Added per-feed
liveness (binance.last_tick_at, hl_price_feed.last_tick_at) with a 180s boot
grace so startup doesn't false-503. Body now includes price_feeds[].
Single-process enforcement (multi-worker safety)
The backend is single-process by design (in-memory scheduler, replay cache,
tp_sl table, price_store). systemd unit lacked the --workers 1 + rationale
that supervisor.conf already had; added it. Added a runtime advisory file
lock (app.main._acquire_singleton_lock): only the leader starts background
tasks; extra workers serve HTTP reads only and log CRITICAL. health/deep now
reports is_leader so the misconfig is visible to monitors.
72 tests pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Batch of the pre-launch audit campaign (BUG-01…14 plus three new features):
Pricing / TP-SL protection
- Add app/services/hl_price_feed.py: supplemental HL allMids poller for
HL-native assets (HYPE, PURR) not listed on Binance. Pumps price_store +
tp_sl_monitor.on_price_tick so bot trades on these assets keep full
stop-loss / take-profit / trailing protection instead of max-hold only.
- Wire feed into main.py lifespan (startup task + graceful shutdown cancel).
Telegram
- Add format_trump_mention + PATH B in _dispatch: crypto-relevant Trump
posts with no directional signal (relevant=True, signal=hold) now alert
the public channel only (no per-subscriber noise).
- Rate limiter (slowapi) on the API; assorted bot/digest fixes.
KOL on-chain
- seed_kol_wallets.py: KOL_FEEDS coverage cross-check; reversibly deactivate
orphaned wallets (handle not in KOL_FEEDS → can never produce divergence)
so the scanner stops burning cycles on them.
Tests / misc
- Fix brittle test_macro_ahr999_uses_same_formula_as_scanner: mock now uses
realistic ms timestamps so the in-progress-day drop fires, matching the
fetcher's bar count (was 0.3179 vs 0.3178 off-by-one).
- Refresh stale notify_signal comment in truth_social.py.
Frontend reduce-action type fix lives in the sibling repo.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
New backend pipeline: 8 free public macro signals fetched in parallel,
upserted once per calendar day, served via /api/macro/{snapshot,history}.
- AHR999 (computed from Binance 200d klines)
- Altcoin Season Index (CoinGecko top-50 30d)
- Fear & Greed (alternative.me)
- BTC dominance, ETH/BTC ratio
- Stablecoin supply (DeFiLlama)
- Spot BTC ETF net flow (Farside)
- BTC perp open interest (Binance fapi)
Each fetcher is independently @_none_on_fail decorated so one outage
can't take down the snapshot; scoring renormalises across whichever
indicators returned a value. Daily cron at 03:00 UTC; on startup a
fire-and-forget bootstrap fills today's row if missing.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Three plumbing fixes + one ops doc that close the gaps from the audit.
scripts/rescore_v5.py
Was overwriting only signal/conf/reasoning/sentiment/relevant/
prefilter_reason/analysis_version. Now also persists target_asset,
category, expected_move_pct — without these the bot can't route
rescored posts correctly (would silently fall back to BTC).
app/schemas.py + app/api/posts.py
TrumpPost response model didn't expose target_asset/category/
expected_move_pct, so the frontend had no way to display "this
signal will trade SOL". Added the three fields + mapping in
_post_to_schema(). Pre-v5 posts return null. No frontend changes
yet — display work is a follow-up.
app/services/hyperliquid.py
HL caps max leverage per asset (BTC/ETH 50×, SOL 20×, memes 3-5×).
set_leverage() always tried to push self._leverage — if user set
30× and bot routed to TRUMP, HL rejected the order and the trade
silently dropped. Added _get_max_leverage() (queries meta()'s
maxLeverage field) and _clip_leverage() that caps to HL's max.
set_leverage now returns the effective leverage so callers can
use it for notional sizing if needed.
deploy/ENCRYPTION_KEY_BACKUP.md
Documented mandatory backup procedure for the symmetric key that
encrypts every user's HL API key. Lost key = all users' bots dead
with no recovery. Includes rotation procedure + quarterly test
step + things-not-to-do list.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
scripts/sweep_500.py:
Parameter grid for capital-preservation oriented configs.
Risk filters: max DD <= 30%, max single loss <= 16% of capital.
scripts/sweep_moonshot.py:
Aggressive grid for one-trade-hits-big strategy.
Looser DD ceiling (50%), prioritizes biggest single-trade upside.
Both run on the local v4 dataset to inform initial subscription
parameter choices for live trading. Re-run after v5 accumulates
enough signals (~6 weeks) to recalibrate.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After deploying v5 analysis.py, run this once to overwrite v4 scores in
the DB with v5's interpretation. Idempotent — skips rows already at v5.
Has --dry-run mode to preview the change without AI calls or DB writes.
Live mode prompts for confirmation (skipped if stdin is non-tty so it
also works under `docker exec`).
Touches only AI-derived columns (signal, ai_confidence, ai_reasoning,
sentiment, relevant, prefilter_reason, analysis_version). Leaves all
market-derived columns intact (price_at_post, price_impact_*) — those
stay accurate regardless of which prompt version interpreted the post.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>