A crypto price alert has one job: tell you when a coin crosses your number, soon enough to matter. I run the server side of CoinPriceAlert, a Node and TypeScript service that checks every user alert every 5 seconds and sends a push, Telegram message or email when one fires. Most of what I now believe about price alerts came from the engine doing the wrong thing in production.

This post covers five of those lessons, with the code that came out of each.

"Checked every 15 seconds" was true and still misleading

The first version looked fine on paper. A timer ran the check every 15 seconds. The prices came from a CoinGecko markets feed, and to stay inside the free quota that feed was cached for five minutes.

So the check ran every 15 seconds against a number that could be five minutes old. The app was telling users the truth about the loop and nothing useful about latency.

The fix was a single websocket to Binance's public !miniTicker@arr stream. It needs no key, has no quota, and sends one message a second carrying every symbol. Each tick lands in a map keyed by ticker:

type Tick = { price: number; open: number; at: number }; const prices = new Map<string, Tick>(); // BTC -> latest USDT price // A live tick older than this is not trusted; fall back to the cached feed. const FRESH_MS = 20_000; 

Every check overlays the live price on top of the cached one. Stocks, gold and anything Binance doesn't list keep the cached price, because a slightly old price beats no price for those.

One trap here. The stream is keyed by ticker, and tickers are not unique. Anyone can deploy a Solana token called "BTC", so a token added by contract address never inherits a price from the ticker map.

A quiet coin is not a frozen coin

The miniTicker stream only sends a symbol when its price changes. Bitcoin changes every second. A calmer top 100 coin can go minutes without a single message.

I found this in the logs: 434 "stale price, skipped" lines in ten hours, naming coins like Algorand, Kaspa, Stellar and Chainlink. They were sitting right on the staleness limit, flipping between checked and not checked from one sweep to the next.

Raising the limit would only move the boundary. The better answer was a second overlay. When a coin's websocket price is older than 3 minutes, the engine pulls a spot price from the exchanges, which costs one request per venue per minute for the whole market:

const stalePrimary = alertCoinIds.filter((id) => { const seen = observedAt.get(id); return seen == null || Date.now() - seen > 3 * 60_000; }); 

The ticker problem comes back here too. A spot price only overrides when exactly one coin in our list owns that ticker, and when a second source matched on coin id doesn't contradict it.

An old price must never decide anything

This one is the rule I'd tell anyone building alerts. Cached price functions are written for charts. When the upstream fails, they serve the last good value forever, which is fine for drawing a line and dangerous for deciding whether a line was crossed.

During an outage that can go two ways. An alert fires on a price from hours ago, or it stays silent through a real crash because the cached number never moved. Nothing in the data tells those apart.

So every price carries the time it was observed, and a price past the limit doesn't get a vote:

const MAX_PRICE_AGE_MS = 20 * 60_000; 

A late alert costs one notification. An alert that fires on a price that was never real costs the reason anyone keeps the app installed.

The number itself needed tuning. It started at 10 minutes. Then I measured DefiLlama, which prices a lot of long tail tokens, and its median price age for those coins was 13 minutes. The 10 minute guard rejected 87% of its prices and left 27% of the catalogue unable to fire at all.

At 20 minutes, a thin token fires in about 13 minutes instead of never. Coins on Binance still fire within seconds, because each coin is judged on its own observation time.

One failed request should never stop every alert

On 7 October the engine stopped sending alerts and said nothing about it.

A restart had emptied the markets cache. Refilling it meant calling CoinGecko, and CoinGecko was refusing almost every call because the monthly quota was spent. The call threw. The check function was wrapped like this:

try { markets = await getMarkets(); } catch { return; } 

That return skipped every alert in the system. No error, no log line, and the "last check" timestamp simply stopped moving. Alerts with their condition met by more than 3% sat unsent until someone went looking.

The top 100 feed is now one price source among several. If it fails, the check logs a warning once a minute and carries on with the websocket, the exchange spot feeds, DefiLlama and CoinPaprika.

A related guard: setInterval fires whether or not the previous sweep has finished. A slow sweep used to run alongside the next one. Now only one sweep runs at a time, and a sweep stuck for two minutes is abandoned so it can't block alerts for good:

function runTick() { if (tickRunning && Date.now() - tickStartedAt < 120_000) return; tickRunning = true; tickStartedAt = Date.now(); tick().catch(onTickError).finally(() => { tickRunning = false; }); } 

Repeat alerts should wait for the price to come back

A small one, but users notice it. If you set an alert at $0.16 and the price runs to $0.20, a naive repeating alert pings you every few minutes for as long as the price stays above the line.

Ours fires once, then disarms. It re-arms only after the price crosses back below the target, and it fires again only on a fresh crossing after a minimum gap:

if (!a.armed) return met ? 'skip' : 'rearm'; // wait for the cross back if (!met) return 'skip'; return sinceLastFire >= gap ? 'fire' : 'skip'; 

What I'd do first next time

Store the observation time next to every price from day one. Most of these bugs come down to the engine not knowing how old its number was. Once every price carries its age, the rest of these fixes take a few lines each.

If you want to see the result, the app is at coinpricealert.io. It's free for 3 alerts, and the iPhone and Android apps need no account. I'm happy to answer questions about the engine in the comments.