Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(liquidations): resolve coin-id links for the /coins liquidations strip when it loads before the markets table

fudjia38dc5df10a5f
diff --git a/docs/coin-pages.md b/docs/coin-pages.md
index 8e4408946..40bc3515e 100644
--- a/docs/coin-pages.md
+++ b/docs/coin-pages.md
@@ -22,6 +22,14 @@ editorial serif headings, hairline borders, mono numerals, light/dark themes.
page.
- Responsive: lower-priority columns collapse at small widths, the coin-name
column stays sticky while the table scrolls horizontally.
+- **Liquidations pulse** — a strip under the global stats bar showing a
+ dominant-side badge (LONG PAIN / SHORT SQUEEZE / BALANCED), 1h long-vs-short
+ liquidated USD bars, and the 3 largest recent liquidations, fed by
+ `/api/coin/liquidations` and polled every 30s (paused while the tab is
+ hidden). Optional enrichment: degrades to a quiet single-line offline state
+ — never fabricated data — when its collector isn't reachable. See
+ [`services/liquidation-collector/README.md`](../services/liquidation-collector/README.md)
+ and [api-reference.md → Liquidations](api-reference.md#liquidations).
### `/coin/:id` — coin detail
@@ -132,6 +140,7 @@ All data is real and fetched at runtime — nothing is hardcoded or sampled:
| `/api/coin/fear-greed` | alternative.me `/fng` (current + history) | 300 s |
| `/api/coin/gas` | public Ethereum RPC `eth_feeHistory` + CoinGecko ETH price | 15 s |
| `/api/coin/news` | cryptocurrency.cv aggregator → first-party RSS fallback | 300 s |
+| `/api/coin/liquidations`| `services/liquidation-collector` (Binance/Bybit/OKX public liquidation WebSocket streams) | 15 s, `503` no-fallback offline |
Full request/response shapes: [api-reference.md → Coin Market Data API](api-reference.md#coin-market-data-api).
@@ -158,7 +167,8 @@ text before they reach the client.
| DeFi / Chains / Stablecoins | `pages/{defi,chains,stablecoins}.html` (+ `src/*.js`, `src/*.css`), APIs in [`api/defi/`](../api/defi) |
| Shared design system | [`src/coin-pages.css`](../src/coin-pages.css) (Source Serif 4 self-hosted in `public/fonts/`) |
| Shared formatters | [`src/shared/coin-format.js`](../src/shared/coin-format.js) — unit-tested in [`tests/coin-format.test.js`](../tests/coin-format.test.js) |
-| API proxies | [`api/coin/`](../api/coin) — `detail.js`, `ohlc.js`, `markets.js`, `global.js`, `fear-greed.js`, `gas.js`, `news.js` |
+| API proxies | [`api/coin/`](../api/coin) — `detail.js`, `ohlc.js`, `markets.js`, `global.js`, `fear-greed.js`, `gas.js`, `news.js`, `liquidations.js` |
+| Liquidations collector | [`services/liquidation-collector/`](../services/liquidation-collector) — standalone always-on Node service (not a Vercel function) |
Routing: `vercel.json` rewrites `/coins`, `/coin/<id>`, `/heatmap`,
`/fear-greed`, `/gas`, and `/compare` to their pages in production; the Vite dev
diff --git a/src/coins-index.js b/src/coins-index.js
index 26717966d..dcc836c84 100644
--- a/src/coins-index.js
+++ b/src/coins-index.js
@@ -367,6 +367,7 @@ const LIQ_POLL_MS = 30_000;
const LIQ_1H_MS = 60 * 60 * 1000;
let liqTimer = null;
let liqLoaded = false;
+let lastLiqData = null; // last successful payload, re-rendered once state.coins loads (see loadCoins().then below) so symbol→id links resolve even when liquidations loads faster than the markets table.
// Resolve a liquidation's ticker symbol to a /coin/:id detail page — only for
// symbols present in the currently loaded markets table (state.coins), per
@@ -464,6 +465,7 @@ async function pollLiquidations() {
if (document.hidden) return;
try {
const data = await getJson('/api/coin/liquidations');
+ lastLiqData = data;
renderLiqPopulated(data);
} catch {
// 503 collector_offline (or any other failure) → quiet offline line, never
@@ -493,6 +495,12 @@ function loadLiquidations() {
// ── Boot ────────────────────────────────────────────────────────────────────
loadStats();
-loadCoins();
+// If the liquidations strip's first poll lands before the markets table finishes
+// loading, its top-3 items resolve no symbol→id links yet (state.coins is still
+// empty). Re-render with the same data once the table is in so those items pick
+// up their /coin/:id links without waiting for the next 30s poll.
+loadCoins().then(() => {
+ if (lastLiqData) renderLiqPopulated(lastLiqData);
+});
loadLiquidations();
wireSearch();