Download console/src/pages/Overview.tsx from bryceweiner/fly-trader: direct link, hf CLI and curl.
- Browser
- Download file 26.6 kB
-
https://huggingface.co/bryceweiner/fly-trader/resolve/main/console/src/pages/Overview.tsx
- Command line
-
hf download hf://bryceweiner/fly-trader/console/src/pages/Overview.tsx
-
curl -L -o Overview.tsx https://huggingface.co/bryceweiner/fly-trader/resolve/main/console/src/pages/Overview.tsx
26.6 kB
| // 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<string, string> = { 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 <button type="button" className="link-btn" title={mint} onClick={() => openInspector({ kind: 'token', chain, mint })}>{token}</button> | |
| } | |
| /** The selector book's KPI row, then the narrative beside the win rate. */ | |
| function SummaryPanel() { | |
| const { chain } = useApp() | |
| const s = useTopic<Summary>('overview.summary', { chain }) | |
| return ( | |
| <Loaded state={s} height={150}> | |
| {(d) => { | |
| const u = d.market.unit, winRate = d.closed ? d.wins / d.closed : null | |
| return ( | |
| <> | |
| <WidgetGrid> | |
| <Widget label={d.label} icon="wealth" value={amount(d.wealth, u)} color={d.live ? 'magenta' : null} help={d.wealth_help} spark={d.spark.length > 1 ? d.spark : null} | |
| delta={d.wealth !== null ? `${signed(d.wealth - d.capital, 4)} ${u} since start` : null} /> | |
| <Widget label="Realized P&L" icon="pnl" value={amount(d.pnl, u, 4, true)} help={d.live ? 'The wallet now, with open positions at cost, minus the starting amount.' : 'Closed trades, after fees and price impact.'} | |
| spark={d.pnl_spark.length > 1 ? d.pnl_spark : null} /> | |
| <Widget label="Closed trades" icon="count" value={int(d.closed)} delta={winRate !== null ? `${Math.round(winRate * 100)}% winners` : null} tone="off" | |
| progress={winRate} /> | |
| <Widget label="Open positions" icon="open" value={int(d.n_open)} delta={d.marked ? `${g(d.exposure ?? 0, 3)} ${u} at cost` : null} tone="off" | |
| progress={d.marked && d.wealth ? Math.min(1, (d.exposure ?? 0) / d.wealth) : null} /> | |
| <Widget label="Drawdown" icon="drawdown" value={pct(d.drawdown, 2, false)} help="Below the book's peak wealth." | |
| spark={d.dd_spark.length > 1 ? d.dd_spark.map((x) => -x) : null} /> | |
| </WidgetGrid> | |
| <div className="row gx-4"> | |
| <div className="col-12 col-xl-8 d-flex"> | |
| <Card title="In plain words" icon="bx-message-square-detail" className="flex-fill"><Md text={d.narrative} /></Card> | |
| </div> | |
| <div className="col-12 col-xl-4 d-flex"> | |
| <Card title="Win rate" icon="target" sub={d.live ? 'closed live trades that made money' : 'closed trades of the selector book that made money'} className="flex-fill" bodyClass="pb-0"> | |
| <RadialGauge value={winRate} label="winners" display={winRate === null ? '—' : `${Math.round(winRate * 100)}%`} height={210} /> | |
| <RowGroup items={[{ label: 'closed', value: int(d.closed) }, { label: 'winners', value: int(d.wins) }, { label: `realized ${u}`, value: num(d.pnl ?? 0, 3, true) }]} /> | |
| </Card> | |
| </div> | |
| </div> | |
| </> | |
| ) | |
| }} | |
| </Loaded> | |
| ) | |
| } | |
| /** 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<Minute>('overview.minute', { chain }) | |
| const now = useNow(1000) | |
| return ( | |
| <Loaded state={m} height={160}> | |
| {(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 ( | |
| <div className="row gx-4"> | |
| <div className="col-12 col-xl-8 d-flex"> | |
| <Card title="This minute" icon="time" sub={caption} className="flex-fill"> | |
| {!d.minute ? <Caption>{d.runner ? 'No minute scored yet.' : 'The trading engine is stopped.'}</Caption> : ( | |
| <Metrics min={250}> | |
| <Metric compact icon="time" label="Minute (UTC)" value={d.minute_hm} /> | |
| <Metric compact icon="layers" label="Tokens traded" value={int(d.mints_traded)} /> | |
| <Metric compact icon="bx-filter-alt" label="Eligible" value={int(d.eligible)} help={d.eligible_help} | |
| progress={d.mints_traded ? d.eligible / d.mints_traded : null} /> | |
| <Metric compact icon="score" label="Best score" value={d.score_max.toFixed(3)} delta={`needs ${d.threshold.toFixed(3)}`} tone="off" | |
| progress={d.threshold > 0 ? Math.max(0, d.score_max) / d.threshold : null} color={d.threshold > 0 && d.score_max >= d.threshold ? 'success' : null} /> | |
| <Metric compact icon="target" label="Picks" value={int(d.picks)} color={d.picks ? 'violet' : null} /> | |
| <Metric compact icon="swap" label="Bought / sold" value={`${d.entered} / ${d.exited}`} /> | |
| </Metrics> | |
| )} | |
| </Card> | |
| </div> | |
| <div className="col-12 col-xl-4 d-flex"> | |
| <Card title="Top scores" icon="chart" sub="the minute's best-scored tokens (score 0..1)" className="flex-fill"> | |
| {d.top.length ? ( | |
| <ProgressList max={1} items={d.top.map((t) => ({ label: <TokenButton chain={chain} mint={t.mint} token={t.token} />, value: t.score.toFixed(3), frac: Math.max(0, t.score) }))} /> | |
| ) : <Caption>{d.minute ? 'No token scored this minute.' : 'Nothing scored yet.'}</Caption>} | |
| </Card> | |
| </div> | |
| </div> | |
| ) | |
| }} | |
| </Loaded> | |
| ) | |
| } | |
| /** 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<Race>('overview.race', { chain }) | |
| if (!r.data) return r.error ? <Callout kind="error">{r.error}</Callout> : null | |
| const d = r.data | |
| if (d.hidden) return null | |
| const u = d.unit | |
| return ( | |
| <div className="row gx-4"> | |
| <div className="col-12 col-xl-8 d-flex"> | |
| <Card title="The race: selector vs plastic fly" icon="race" sub={d.success ? null : d.caption} className="flex-fill"> | |
| {r.error && <Callout kind="error">{r.error} (showing the last good data)</Callout>} | |
| {d.success && <Callout kind="success" icon="swap">{d.success}</Callout>} | |
| {(d.series ?? []).length > 0 ? <LineChart series={d.series!} height={300} yFormat={(v) => `${v.toFixed(2)} ${u}`} /> : <Caption>No marks in the last 30 days yet.</Caption>} | |
| </Card> | |
| </div> | |
| <div className="col-12 col-xl-4"> | |
| <div className="d-flex flex-column gap-4 mb-4"> | |
| {(d.metrics ?? []).map((m) => ( | |
| <Widget key={m.book} label={m.title} icon={BOOK_ICON[bookKind(m.book)]} value={amount(m.pnl, u, 4, true)} delta={`${m.n} trades`} tone="off" | |
| help="Realized P&L of closed trades (bars: each day's)." spark={m.daily.some((x) => x !== 0) ? m.daily : null} sparkType="bar" | |
| color={bookKind(m.book) === 'live' ? 'danger' : null} /> | |
| ))} | |
| </div> | |
| </div> | |
| </div> | |
| ) | |
| } | |
| /** 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<Rising>('overview.rising', { chain }) | |
| const [edit, setEdit] = useState<string | null>(null) // the time being typed; null: the saved one | |
| if (!r.data) return r.error ? <Callout kind="error">{r.error}</Callout> : 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 ( | |
| <Card title={title} icon="up" sub={sub} actions={( | |
| <ActionButton label={`Start the ${d.days}-day test`} icon="play" name="overview.rising_start" disabled={d.observer} | |
| help={d.observer ? 'This console only observes: start it from the console that hosts the workers.' : undefined} | |
| confirm={{ title: 'Start the paper test?', confirmLabel: 'Start', body: <>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.</> }} /> | |
| )}> | |
| <Caption>No test is running.</Caption> | |
| </Card> | |
| ) | |
| } | |
| 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 ( | |
| <Card title={title} icon="up" sub={sub}> | |
| {r.error && <Callout kind="error">{r.error} (showing the last good data)</Callout>} | |
| {d.live_since && <Callout kind="success" icon="payments">Live since {localText(d.live_since)}: the wallet doubles these stakes.</Callout>} | |
| {d.held && <Callout kind="warning">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.</Callout>} | |
| <Metrics min={170}> | |
| <Metric compact label="Test book" icon="up" value={amount(d.book?.pnl, u, 4, true)} delta={stat(d.book)} tone="off" help="Realized P&L of paper_rising since the test began." /> | |
| <Metric compact label="Selector" icon={BOOK_ICON.selector} value={amount(d.selector?.pnl, u, 4, true)} delta={stat(d.selector)} tone="off" help="Realized P&L of paper_selector over the same time: the same picks at plain stakes." /> | |
| <Metric compact label="Doubled trades" icon="target" value={amount(d.doubled?.pnl, u, 4, true)} delta={`${stat(d.doubled)}${d.doubled?.mean == null ? '' : ` · ${pct(d.doubled.mean, 1)}`}`} tone="off" help="What the go-live judges: its closed doubled trades must have made money." /> | |
| <Metric compact label="Rest of the trades" icon="count" value={amount(d.rest?.pnl, u, 4, true)} delta={`${stat(d.rest)}${d.rest?.mean == null ? '' : ` · ${pct(d.rest.mean, 1)}`}`} tone="off" /> | |
| <Metric compact label="Breadth, 6 h" icon="pulse" value={d.breadth_chg == null ? '—' : `${num(d.breadth_chg * 100, 1, true)} pts`} delta={d.rising == null ? null : d.rising ? 'rising' : `needs ${num((d.rise ?? 0) * 100, 1, true)} pts`} tone="off" help="Change over 6 hours in the share of coins (pool at least 10 SOL) up on the hour." /> | |
| </Metrics> | |
| {(d.series ?? []).length > 0 && <LineChart series={d.series!} height={220} yFormat={(v) => `${v.toFixed(3)} ${u}`} />} | |
| <div className="d-flex flex-wrap align-items-end gap-2 mt-3"> | |
| <div> | |
| <label className="form-label" htmlFor="rising-go-live">Go-live (this machine's time)</label> | |
| <input id="rising-go-live" className="form-control" type="datetime-local" max="9999-12-31T23:59" value={when} disabled={d.observer} onChange={(e) => setEdit(e.target.value)} /> | |
| </div> | |
| <ActionButton label="Save" icon="calendar" name="overview.rising_go_live" body={{ at: iso }} variant="primary" disabled={d.observer || !iso || when === saved} onDone={() => 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.' : ''}</> }} /> | |
| <ActionButton label="No date" icon="trash" name="overview.rising_go_live" body={{ at: null }} disabled={d.observer || !d.go_live_at} onDone={() => 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.</> }} /> | |
| </div> | |
| {!d.live_since && !d.held && <Caption>{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)}.</Caption>} | |
| </Card> | |
| ) | |
| } | |
| /** 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<Book>('overview.book', { chain }) | |
| const sellCol = (d: Book): Col<Position> => ({ | |
| key: 'sell', label: '', value: () => '', | |
| render: (r) => ( | |
| <ActionButton label="Sell now" icon="payments" name="overview.sell_now" body={{ chain, position_id: r.id }} variant="outline-danger" disabled={d.observer} | |
| help={d.observer ? 'This console only observes: sell from the console that hosts the workers.' : undefined} | |
| confirm={{ | |
| title: `Sell ${r.token} now?`, confirmLabel: 'Sell now', danger: true, | |
| body: <>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<Position>[] => [ | |
| ...(d.live && d.sell ? [sellCol(d)] : []), | |
| { key: 'token', label: 'token', render: (r) => <TokenButton chain={chain} mint={r.mint} token={r.token} /> }, | |
| { 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 : <span className={`text-${tone(r.ret)}`}>{pctPts(r.ret, 2, true)}</span>) }, | |
| ] | |
| return ( | |
| <div className="row gx-4"> | |
| <div className="col-12 col-xl-5 d-flex"> | |
| <Card title={b.data?.title ?? 'Paper wealth'} icon="wealth" sub={b.data?.sub ?? 'the selector book since it started'} className="flex-fill"> | |
| <Loaded state={b} height={260}> | |
| {(d) => d.history.length ? <LineChart series={[{ name: 'wealth', data: d.history }]} height={280} yFormat={(v) => `${v.toFixed(2)} ${d.unit}`} /> : <Caption>No marks yet.</Caption>} | |
| </Loaded> | |
| </Card> | |
| </div> | |
| <div className="col-12 col-xl-7 d-flex"> | |
| <Card title="Open positions" icon="open" className="flex-fill"> | |
| <Loaded state={b}> | |
| {(d) => d.positions.length ? <DataTable rows={d.positions} cols={cols(d)} pageSize={10} filename="open-positions" compact /> : <Caption>None open.</Caption>} | |
| </Loaded> | |
| </Card> | |
| </div> | |
| </div> | |
| ) | |
| } | |
| 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<Setups>('overview.setups') | |
| return ( | |
| <Card title={`Setups · ${s.data?.n_days ?? 30} days`} icon="target" | |
| sub="the buying chances the selector found each UTC day, and the trades it took · fewer setups is a quieter market, not a blocked bot"> | |
| <Loaded state={s} height={300}> | |
| {(d) => ( | |
| <div className="row g-4"> | |
| {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 ( | |
| <div key={c.chain} className={`col-12 ${d.chains.length > 1 ? 'col-xl-6' : ''}`}> | |
| <div className="d-flex align-items-baseline gap-2 mb-1"> | |
| <h6 className="m-0" style={{ color: '#fff' }}>{c.name}</h6> | |
| <span className="caption m-0">{int(c.setups)} setups · {int(c.trades)} selector trades · {int(c.live)} live</span> | |
| </div> | |
| <BarChart categories={c.days.map((x, i) => (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) && ( | |
| <Caption> | |
| {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.'} | |
| </Caption> | |
| )} | |
| </div> | |
| ) | |
| })} | |
| </div> | |
| )} | |
| </Loaded> | |
| <Caption> | |
| 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. | |
| </Caption> | |
| </Card> | |
| ) | |
| } | |
| 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<Hours>('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 ( | |
| <Card title="Trades by hour of day" icon="bx-time-five" | |
| sub={`every trade ever entered, by the hour it opened (${tz === 'UTC' ? 'UTC' : localLabel.toLowerCase()}) · the larger the slice, the busier the hour`} | |
| actions={<> | |
| <Segmented options={['all', 'live'] as const} value={scope} onChange={setScope} labels={{ all: 'All books', live: 'Live' }} /> | |
| <Segmented options={['UTC', 'local'] as const} value={tz} onChange={setTz} labels={{ UTC: 'UTC', local: localLabel }} /> | |
| </>}> | |
| <Loaded state={h} height={420}> | |
| {(d) => ( | |
| <div className="row g-4"> | |
| {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 ( | |
| <div key={c.chain} className={`col-12 ${d.chains.length > 1 ? 'col-xl-6' : ''}`}> | |
| <div className="d-flex align-items-baseline gap-2 mb-1"> | |
| <h6 className="m-0" style={{ color: '#fff' }}>{c.name}</h6> | |
| <span className="caption m-0">{int(total)} trades{scope === 'live' ? ' with real money' : ''}</span> | |
| </div> | |
| {total ? ( | |
| <> | |
| <HourWheel buckets={b} unit={c.unit} shift={shift} /> | |
| <div className="d-flex flex-wrap gap-2 justify-content-center mt-1"> | |
| {ranked.slice(0, 3).map((x, i) => ( | |
| <span key={x.hour} className="fbadge" style={{ background: hourColor(x.hour), color: '#120a18' }}> | |
| #{i + 1} {pad2(x.hour)}:00 · {int(x.trades)} ({((x.trades / total) * 100).toFixed(1)}%) | |
| </span> | |
| ))} | |
| <span className="fbadge gray">quietest {pad2(quiet.hour)}:00 · {int(quiet.trades)}</span> | |
| </div> | |
| </> | |
| ) : <Caption>{scope === 'live' ? 'No live trades on this chain yet.' : 'No trades on this chain yet.'}</Caption>} | |
| </div> | |
| ) | |
| })} | |
| </div> | |
| )} | |
| </Loaded> | |
| <Caption>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.</Caption> | |
| </Card> | |
| ) | |
| } | |
| export default function Overview() { | |
| return ( | |
| <> | |
| <PageHead title="Overview" icon="bx-home-alt" /> | |
| <SummaryPanel /> | |
| <BookPanel /> | |
| <BrainPanel variant="memecoin" /> | |
| <ThisMinute /> | |
| <RacePanel /> | |
| <RisingPanel /> | |
| <SetupsPanel /> | |
| <HoursPanel /> | |
| <TickerCard /> | |
| </> | |
| ) | |
| } | |