// Overview, laid out like Dashtreme's index: the selector book's KPI widgets, what the system is doing in plain words // beside the win rate, the money's book (its wealth and open positions), the fly's brain, this minute's scoring with the top // scores, the race between the selector and the plastic fly, the rising + clean test and its go-live, the selector's setups // per day, and the live ticker (ui/api/overview.py; the brain ui/api/brain.py). import { useState } from 'react' import { BrainPanel } from '../brain' import { PageHead } from '../components/ChainPicker' import { BarChart, LineChart, RadialGauge, type Series } from '../components/Charts' import { DataTable, type Col } from '../components/DataTable' import { ActionButton } from '../components/feedback' import { HourWheel, hourColor, type HourBucket } from '../components/HourWheel' import { Callout, Caption, Card, Loaded, Md, Metric, Metrics, ProgressList, RowGroup, Segmented, Widget, WidgetGrid } from '../components/ui' import { useApp, type Market } from '../context' import { TickerCard } from '../fly/Ticker' import { ago, amount, int, num, pct, pctPts, tone } from '../lib/format' import { useNow, useStored, useTopic } from '../lib/hooks' type Summary = { market: Market narrative: string marked: boolean wealth: number | null exposure: number | null n_open: number drawdown: number | null capital: number closed: number pnl: number | null wins: number spark: number[] pnl_spark: number[] dd_spark: number[] wealth_help: string live: boolean label: string } type Top = { mint: string; token: string; score: number } type Minute = { unit: string runner: boolean trading: string trading_why: string scored_at: string | null minute: string | null minute_hm: string | null mints_traded: number eligible: number score_max: number threshold: number picks: number entered: number exited: number latency_s: number | null top: Top[] eligible_help: string } type RaceBook = { book: string; title: string; pnl: number | null; n: number; daily: number[] } type Race = { hidden: boolean; unit: string; handover?: boolean; success?: string | null; caption?: string | null; metrics?: RaceBook[]; series?: Series[]; days?: string[] } type RisingStat = { closed: number; open: number; pnl: number; mean: number | null } type Rising = { hidden: boolean; running?: boolean; observer?: boolean; days?: number; unit?: string; started_at?: string; go_live_at?: string | null live_since?: string | null; held?: { trades: number; pnl_sol: number; go_live_at: string } | null; breadth_chg?: number | null; rise?: number; rising?: boolean | null book?: RisingStat; selector?: RisingStat; doubled?: RisingStat; rest?: RisingStat; series?: Series[] } type Position = { id: number; mint: string; token: string; strategy: string; held_min: number; exits_in_min: number; cost: number; ret: number | null correctness?: number | null } type Book = { unit: string; history: [string, number][]; positions: Position[]; live?: boolean; book?: string; title?: string; sub?: string; observer?: boolean sell?: { from_pct: number; to_pct: number } } /** Python's %g: significant digits, trailing zeros dropped, an exponent outside 1e-4..1e±digits. */ function g(x: number | null | undefined, digits = 6): string { if (x === null || x === undefined || !Number.isFinite(x)) return '—' if (x === 0) return '0' const [m, e] = x.toExponential(digits - 1).split('e'), exp = Number(e) if (exp < -4 || exp >= digits) return `${m.includes('.') ? m.replace(/\.?0+$/, '') : m}e${exp < 0 ? '-' : '+'}${String(Math.abs(exp)).padStart(2, '0')}` return String(Number(x.toPrecision(digits))) } const signed = (x: number, nd: number) => `${x >= 0 ? '+' : ''}${x.toFixed(nd)}` const BOOK_ICON: Record = { selector: 'psychology', fly: 'neurology', live: 'payments' } const bookKind = (book: string) => (book.startsWith('live') ? 'live' : book.endsWith('fly') ? 'fly' : 'selector') function TokenButton({ chain, mint, token }: { chain: string; mint: string; token: string }) { const { openInspector } = useApp() return } /** The selector book's KPI row, then the narrative beside the win rate. */ function SummaryPanel() { const { chain } = useApp() const s = useTopic('overview.summary', { chain }) return ( {(d) => { const u = d.market.unit, winRate = d.closed ? d.wins / d.closed : null return ( <> 1 ? d.spark : null} delta={d.wealth !== null ? `${signed(d.wealth - d.capital, 4)} ${u} since start` : null} /> 1 ? d.pnl_spark : null} /> 1 ? d.dd_spark.map((x) => -x) : null} />
) }}
) } /** This minute's scoring as compact KPI tiles, with the top scores as a progress list beside it. */ function ThisMinute() { const { chain } = useApp() const m = useTopic('overview.minute', { chain }) const now = useNow(1000) return ( {(d) => { const caption = d.minute ? `Scored ${ago(d.scored_at, now)}` + (d.latency_s !== null && d.latency_s !== undefined ? ` · ${Number(d.latency_s).toFixed(0)} s after the minute closed` : '') + (d.trading !== 'trading' ? ` · ${d.trading_why}` : '') : null return (
{!d.minute ? {d.runner ? 'No minute scored yet.' : 'The trading engine is stopped.'} : ( 0 ? Math.max(0, d.score_max) / d.threshold : null} color={d.threshold > 0 && d.score_max >= d.threshold ? 'success' : null} /> )}
{d.top.length ? ( ({ label: , value: t.score.toFixed(3), frac: Math.max(0, t.score) }))} /> ) : {d.minute ? 'No token scored this minute.' : 'Nothing scored yet.'}}
) }}
) } /** The race: wealth by book as a big area chart, the three 14-day P&L widgets beside it. */ function RacePanel() { const { chain } = useApp() const r = useTopic('overview.race', { chain }) if (!r.data) return r.error ? {r.error} : null const d = r.data if (d.hidden) return null const u = d.unit return (
{r.error && {r.error} (showing the last good data)} {d.success && {d.success}} {(d.series ?? []).length > 0 ? `${v.toFixed(2)} ${u}`} /> : No marks in the last 30 days yet.}
{(d.metrics ?? []).map((m) => ( x !== 0) ? m.daily : null} sparkType="bar" color={bookKind(m.book) === 'live' ? 'danger' : null} /> ))}
) } /** A time as a datetime-local input's value: this machine's local time, to the minute. */ const localInput = (iso: string) => { const d = new Date(iso) return new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 16) } const localText = (iso: string) => localInput(iso).replace('T', ' ') /** The rising + clean paper test: the test book against the selector's since it started, and the go-live, set here. */ function RisingPanel() { const { chain } = useApp() const r = useTopic('overview.rising', { chain }) const [edit, setEdit] = useState(null) // the time being typed; null: the saved one if (!r.data) return r.error ? {r.error} : null const d = r.data if (d.hidden) return null const title = 'Strategy 1: rising + clean' const sub = 'A selector pick takes twice its stake when the market is recovering and the launch was clean.' if (!d.running) { return ( A paper book takes the selector's picks with these stakes doubled, beside the selector's own book. Nothing changes on the wallet. The go-live is set {d.days} days out, and you can move it here. }} /> )}> No test is running. ) } const u = d.unit ?? 'SOL' const saved = d.go_live_at ? localInput(d.go_live_at) : '' const when = edit ?? saved const parsed = when ? new Date(when) : null // a year out of range is an invalid date, not a crash const iso = parsed && !Number.isNaN(parsed.getTime()) ? parsed.toISOString() : null const stat = (s?: RisingStat) => `${s?.closed ?? 0} closed · ${s?.open ?? 0} open` return ( {r.error && {r.error} (showing the last good data)} {d.live_since && Live since {localText(d.live_since)}: the wallet doubles these stakes.} {d.held && Stayed on paper at {localText(d.held.go_live_at)}: {d.held.trades} doubled trades made {amount(d.held.pnl_sol, u, 4, true)}. Set a new go-live below.} {(d.series ?? []).length > 0 && `${v.toFixed(3)} ${u}`} />}
setEdit(e.target.value)} />
setEdit(null)} confirm={{ title: `Go-live ${iso ? localText(iso) : ''}?`, confirmLabel: 'Save', danger: true, body: <>At that time the test is judged. If its doubled trades have made money, the wallet starts doubling these stakes. If not, it stays on paper and the date clears.{d.live_since ? ' The wallet goes back to plain stakes until then.' : ''} }} /> setEdit(null)} confirm={{ title: 'Clear the go-live?', confirmLabel: 'Clear', body: <>The wallet keeps plain stakes until you set a date{d.live_since ? ', from its next buy' : ''}. The paper test keeps running. }} />
{!d.live_since && !d.held && {d.go_live_at ? `Goes live ${localText(d.go_live_at)} if the doubled trades have made money by then.` : 'No go-live date: the wallet keeps plain stakes.'} Test started {ago(d.started_at)}.}
) } /** The money's book: its whole wealth history, and the open positions (a live one can be sold now, after a confirmation). */ function BookPanel() { const { chain, market } = useApp() const b = useTopic('overview.book', { chain }) const sellCol = (d: Book): Col => ({ key: 'sell', label: '', value: () => '', render: (r) => ( Sells all of it from the {market?.name ?? chain} wallet now, at market: slippage from {d.sell?.from_pct}% stepping up to at most {d.sell?.to_pct}%. The result is booked on the live book. Cost {g(r.cost, 4)} {d.unit}{r.ret === null ? '' : `, ${pctPts(r.ret, 2, true)} gross at the last mark`}. The fly's paper book keeps its own position. A sale cannot be undone., }} /> ), }) const cols = (d: Book): Col[] => [ ...(d.live && d.sell ? [sellCol(d)] : []), { key: 'token', label: 'token', render: (r) => }, { key: 'strategy', label: 'strategy' }, { key: 'correctness', label: 'correctness', num: true, render: (r) => (r.correctness == null ? '—' : pct(r.correctness, 0, false)) }, { key: 'held_min', label: 'held (min)', num: true, render: (r) => num(r.held_min, 0) }, { key: 'exits_in_min', label: 'exits in (min)', num: true, render: (r) => num(r.exits_in_min, 0) }, { key: 'cost', label: `cost (${d.unit})`, num: true, render: (r) => g(r.cost, 4) }, { key: 'ret', label: 'return (gross)', num: true, render: (r) => (r.ret === null ? null : {pctPts(r.ret, 2, true)}) }, ] return (
{(d) => d.history.length ? `${v.toFixed(2)} ${d.unit}`} /> : No marks yet.}
{(d) => d.positions.length ? : None open.}
) } type SetupDay = { day: string; setups: number | null; trades: number | null; live: number; ran: number } type SetupChain = { chain: string; name: string; setups: number; trades: number; live: number; days: SetupDay[] } type Setups = { tz: string; n_days: number; gap_min: number; chains: SetupChain[] } const dayLabel = (iso: string) => new Date(`${iso}T00:00:00Z`).toLocaleDateString('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC' }) const PARTIAL = 0.9 // a day the selector book ran less of than this is flagged /** The selector's setups per UTC day over 30 days, beside the trades it took: one chart per chain, Solana on the left, * Robinhood Chain on the right. Fewer setups is a quieter market; setups without trades are vetoes. */ function SetupsPanel() { const s = useTopic('overview.setups') return ( {(d) => (
{d.chains.map((c) => { const last = c.days.length - 1 const partial = c.days.filter((x, i) => i < last && x.setups !== null && x.ran < PARTIAL) const off = c.days.filter((x) => x.setups === null).length return (
1 ? 'col-xl-6' : ''}`}>
{c.name}
{int(c.setups)} setups · {int(c.trades)} selector trades · {int(c.live)} live
(i === last ? 'today' : dayLabel(x.day)))} height={260} series={[{ name: 'setups', data: c.days.map((x) => x.setups) }, { name: 'selector trades', data: c.days.map((x) => x.trades) }]} yFormat={(v) => (Number.isInteger(v) ? int(v) : '')} /> {(partial.length > 0 || off > 0) && ( {off > 0 && `${off} day${off > 1 ? 's' : ''} without a bar: the selector book was not running. `} {partial.length > 0 && `Ran only part of ${partial.slice(-6).map((x) => `${dayLabel(x.day)} (${Math.round(x.ran * 100)}%)`).join(', ')}`} {partial.length > 6 && ` and ${partial.length - 6} earlier day${partial.length > 7 ? 's' : ''}`} {partial.length > 0 && ': fewer setups there say nothing of the market.'} )}
) })}
)}
A setup is a token the selector picked while not holding it; its picks less than {s.data?.gap_min ?? 30} minutes apart count once. A setup it did not trade was vetoed (dump veto, win filter). Days are UTC.
) } type HourChain = { chain: string; name: string; unit: string; all: HourBucket[]; live: HourBucket[] } type Hours = { tz: string; archives: number; chains: HourChain[] } const LOCAL_SHIFT = Math.round(-new Date().getTimezoneOffset() / 60) const pad2 = (h: number) => String(h).padStart(2, '0') /** Every trade ever entered, by hour of day: one wheel per chain, Solana on the left, Robinhood Chain on the right. */ function HoursPanel() { const h = useTopic('overview.hours') const [scope, setScope] = useStored<'all' | 'live'>('hours_scope', 'all') const [tz, setTz] = useStored<'UTC' | 'local'>('hours_tz', 'UTC') const shift = tz === 'local' ? LOCAL_SHIFT : 0 const localLabel = `Local (UTC${LOCAL_SHIFT >= 0 ? '+' : ''}${LOCAL_SHIFT})` return ( }> {(d) => (
{d.chains.map((c) => { const b = c[scope] const total = b.reduce((s, x) => s + x.trades, 0) const shown = Array.from({ length: 24 }, (_, i) => ({ ...(b[(((i - shift) % 24) + 24) % 24] ?? { trades: 0, closed: 0, wins: 0, pnl: 0 }), hour: i })) // the hour shown const ranked = [...shown].sort((x, y) => y.trades - x.trades) const quiet = [...shown].sort((x, y) => x.trades - y.trades)[0] return (
1 ? 'col-xl-6' : ''}`}>
{c.name}
{int(total)} trades{scope === 'live' ? ' with real money' : ''}
{total ? ( <>
{ranked.slice(0, 3).map((x, i) => ( #{i + 1} {pad2(x.hour)}:00 · {int(x.trades)} ({((x.trades / total) * 100).toFixed(1)}%) ))} quietest {pad2(quiet.hour)}:00 · {int(quiet.trades)}
) : {scope === 'live' ? 'No live trades on this chain yet.' : 'No trades on this chain yet.'}}
) })}
)}
Counts every memecoin position ever opened, paper and live: the positions table plus every reset's archive (data/pg_archive). Hover a slice for its trades, win rate and realized P&L.
) } export default function Overview() { return ( <> ) }