Optic
Overview
Section titled “Overview”Terminal trading dashboard. A Rust TUI built with Ratatui that reads Cortex and Synapse SQLite databases directly via rusqlite. No JS runtime, no network calls — just local DB reads.
How it works
Section titled “How it works”Startup (apps/optic/src/main.rs)
Section titled “Startup (apps/optic/src/main.rs)”- Parse CLI args: first positional arg = Cortex DB path,
--synapse <path>= Synapse DB path - Open CortexDb (required) and optionally SynapseDb
- Initial data refresh
- Enter Crossterm alternate screen, start event loop
Event loop
Section titled “Event loop”- Auto-refreshes every 5 seconds
- Polls for keyboard events between refreshes
- Modal popups for news detail and signal detail
View modes
Section titled “View modes”Market view (1 key):
- Prices table — Token symbols, current price, 24h/7d change, volume
- Price chart — Braille-rendered 24h sparkline (cycle tokens with
c) - News feed — Scrollable list with source, time, linked tokens. Enter for detail modal,
oto open URL. - Signals — Buy/sell/hold with confidence, timeframe (24h/4w), reasoning preview. Enter for detail modal.
- Knowledge graph — Recent edges: source -> relation -> target with weight
Trading view (2 key, requires Synapse connection):
- Positions — Open positions with entry/current price, size, unrealized P&L, stop-loss/take-profit
- Trades — Recent buy/sell executions
- Signal log — Every signal processed: opened, closed, or skipped with reason
- Risk events — Stop-loss, take-profit, drawdown halt events
Portfolio bar (shown when Synapse connected):
- NAV, cash, drawdown %, return %, HALTED/LIVE status
Keybinds
Section titled “Keybinds”| Key | Action |
|---|---|
q | Quit |
r | Manual refresh |
Tab | Cycle focused panel |
j/k or arrows | Scroll |
c | Cycle price chart token (market view) |
Enter | Detail modal (news/signals) |
o | Open news URL in browser (in detail modal) |
a | Queue analyze command for Cortex |
1 | Market view |
2 | Trading view |
Esc | Close modal |
Command queue
Section titled “Command queue”Pressing a inserts an “analyze” command into Cortex’s commands table. Cortex picks it up on its next command poll (every 10s) and runs signal analysis. Status shows in the status bar.
Key files
Section titled “Key files”| File | Role |
|---|---|
src/main.rs | CLI args, DB connections, terminal setup, event loop |
src/db.rs | CortexDb + SynapseDb structs. Read-only rusqlite queries. |
src/ui.rs | All Ratatui rendering: panels, tables, charts, modals, status bar |
Database access
Section titled “Database access”Optic reads databases read-only and never writes (except the command queue insert):
From Cortex DB (CortexDb):
tracked_tokens— Token symbolsprice_snapshots— Current + historical pricesnews_items— News articlessignals— Trading signalsgraph_nodes+graph_edges— Knowledge graphmemories— Memory counts for statscommands— Insert analyze commands
From Synapse DB (SynapseDb):
portfolio_state— NAV, cash, drawdownpositions— Open positionstrades— Recent tradessignal_log— Signal processing historyrisk_events— Risk management events
Building
Section titled “Building”just optic # Run (debug build)just optic-build # Release buildDependencies: Rust toolchain, sqlite3 system library (or bundled via rusqlite feature).