ASK KNOX
beta
LESSON 285

Last Real Trade as a Metric

Bot liveness dashboards. 'Hours since last real trade' as a first-class metric, displayed alongside test pass rate. Separate axis from code quality — and the single number that would have caught Agent Framework before the ceiling analysis debate.

6 min read·Tests Pass ≠ System Works

The simplest metric that would have caught the Agent Framework failure is "hours since last real trade." It is one number. It is easy to compute. It cannot hide silence behind counting tricks. And it would have been red for weeks before the session retro surfaced the actual root cause.

The Metric

-- PostgreSQL
SELECT
  EXTRACT(EPOCH FROM (NOW() - MAX(filled_at))) / 3600 AS hours_since_last_real_trade
FROM agent_trades
WHERE status = 'filled';

-- MySQL equivalent: TIMESTAMPDIFF(SECOND, MAX(filled_at), NOW()) / 3600
-- SQLite equivalent: (strftime('%s','now') - strftime('%s', MAX(filled_at))) / 3600.0

One row. One number. Small number = recent activity. Large number = silence. Push it to your metrics backend as bot.liveness.hours_since_last_trade and display it on the bot's main dashboard.

Why It Works

A staleness counter captures a property that count-based metrics cannot. "Trades today" resets at midnight and can read zero on both a quiet day and a fully broken bot. "Hours since last real trade" is monotonically increasing until a real trade resets it, so extended silence accumulates visibly no matter how you slice the display window.

This matters because the failure modes that matter most are the long ones. A bot that stops trading for an hour is probably fine — one of its data sources is slow, one of its signals is noisy, nothing to do. A bot that stops trading for 500 hours is not fine. The staleness counter tells the difference at a glance.

The same counter reads differently depending on how high it has climbed. The bands above turn one monotonic number into a decision: ignore it, watch it, or page someone — and the boundary between watch and page is set per bot, scaled to its expected trading cadence.

Inline Diagram — The Dashboard Layout

The Dashboard Rule

Every bot dashboard should have two columns: code integrity on the left, operational validity on the right. The left column is the CI-style metrics everyone builds by default. The right column is the set of metrics that directly measure whether the bot is producing its intended outcomes.

Both columns appear on the same screen. No tab-switching. No drill-down. A glance should be enough to see whether the bot is healthy in both senses — and the Agent Framework pattern (left column fully green, right column fully red) should be impossible to miss.

The Rule

Liveness is a staleness counter, not a count. One number per bot. Displayed next to code integrity metrics so the gap is visible. Alerted against a bot-specific threshold. The Agent Framework failure would have been unmissable with this one metric — and adding it across the bot ecosystem is the cheapest post-incident insurance policy available.