Nice write-up, the sensor and router framing is a good way to think about it. Two things worth adding before running this unattended: the plain WebSocket has no reconnect, and Binance closes every connection after 24 hours, so the watcher quietly stops. Also, price > 100000 fires on every tick above the line, so the agent gets spammed (you mention debouncing; an edge check covers most of it).
Disclosure: we maintain the binance npm SDK, which handles heartbeats, reconnects and resubscribes. The same watcher with it:
import { WebsocketClient, isWsFormattedTrade } from 'binance';
const ws = new WebsocketClient({ beautify: true });
let above = false;
ws.on('formattedMessage', async (data) => {
if (!isWsFormattedTrade(data)) return;
const isAbove = data.price > 100000;
if (isAbove && !above) await triggerAgent(data.price);
above = isAbove;
});
ws.on('reconnected', (data) => console.log('[Watcher] reconnected', data?.wsKey));
ws.on('exception', console.error);
ws.subscribeSpotTrades('BTCUSDT');