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.

feat: add Coin Market Data API with endpoints for coin details, price series, markets, global stats, and related news

qrqk79c8aaf4cefb
diff --git a/docs/api-reference.md b/docs/api-reference.md
index a2dda9e7e..cead38ac0 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -954,6 +954,116 @@ Each asset has its own SIWX grant key: the endpoint passes a `resourceUrlBuilder
---
+## Coin Market Data API
+
+Public, unauthenticated, CORS-open proxies over CoinGecko (plus a news
+aggregator) that power the [/coins](https://three.ws/coins) markets index and
+the `/coin/:id` detail pages. Responses are CDN-cached (30–300 s), so polling
+faster than the cache window returns the same payload. See
+[docs/coin-pages.md](coin-pages.md) for the product surface.
+
+### Coin detail
+
+```
+GET /api/coin/detail?id=<coingecko-id>
+GET /api/coin/detail?contract=<solana-mint>
+```
+
+**Query parameters**
+
+| Parameter | Type | Description |
+|-----------|------|-------------|
+| `id` | string | CoinGecko coin id (lowercase slug). Required unless `contract` is given |
+| `contract` | string | Base58 Solana mint address — resolves via the contract lookup |
+
+**Response**
+
+```json
+{
+ "coin": {
+ "id": "…", "symbol": "…", "name": "…", "image": "https://…", "rank": 1,
+ "categories": ["…"],
+ "description": "plain text, HTML stripped server-side",
+ "links": { "homepage": "…", "twitter": "…", "reddit": "…", "telegram": "…", "github": "…", "explorers": ["…"] },
+ "platforms": { "<chain>": "<contract address>" },
+ "market": {
+ "price": 0, "market_cap": 0, "fdv": 0, "volume_24h": 0,
+ "high_24h": 0, "low_24h": 0, "change_24h_abs": 0,
+ "change_pct": { "h24": 0, "d7": 0, "d30": 0, "y1": 0 },
+ "circulating": 0, "total": 0, "max": 0,
+ "ath": 0, "ath_date": "…", "ath_change_pct": 0, "atl": 0, "atl_date": "…"
+ },
+ "last_updated": "…"
+ }
+}
+```
+
+Errors: `404 not_found` (unknown id/contract), `502 upstream_error`.
+
+---
+
+### Price series
+
+```
+GET /api/coin/ohlc?id=<coingecko-id>&days=<1|7|30|90|365>
+```
+
+Returns `{ "data": [[timestamp_ms, price], …], "days": 30 }` — close prices at
+upstream-chosen granularity (5-minutely for 1 day, hourly to 90 days, daily
+beyond).
+
+---
+
+### Markets table / coin search
+
+```
+GET /api/coin/markets?page=1&per_page=100 # ranked rows, 7d sparklines
+GET /api/coin/markets?q=<text> # type-ahead search, top 10
+```
+
+Table rows: `{ id, symbol, name, image, rank, price, change_24h, change_7d,
+market_cap, volume_24h, sparkline: [number, …] }` (sparklines downsampled to
+≤32 points). Search results: `{ id, name, symbol, thumb, rank }`.
+
+---
+
+### Global market stats
+
+```
+GET /api/coin/global
+```
+
+**Response**
+
+```json
+{
+ "market": {
+ "market_cap_usd": 0, "volume_24h_usd": 0, "market_cap_change_pct_24h": 0,
+ "active_coins": 0,
+ "dominance": [{ "symbol": "…", "pct": 0 }]
+ },
+ "fear_greed": { "value": 0, "label": "…" }
+}
+```
+
+`dominance` holds the top-2 assets by market-cap share, largest first. Either
+half may be `null` if its upstream is briefly unavailable.
+
+---
+
+### Related news
+
+```
+GET /api/coin/news?q=<coin name>&limit=8
+```
+
+Returns `{ "articles": [{ title, link, description, image, source,
+published_at }], "source": "cryptocurrency.cv" | "rss" }`. Primary upstream is
+the cryptocurrency.cv aggregator; on failure it reads the same first-party RSS
+feeds directly (`source: "rss"`).
+
+---
+
## Config API
```
diff --git a/docs/coin-pages.md b/docs/coin-pages.md
new file mode 100644
index 000000000..9d06915ff
--- /dev/null
+++ b/docs/coin-pages.md
@@ -0,0 +1,83 @@
+# Global Markets & Coin Detail Pages
+
+three.ws has always had deep coverage of pump.fun launches (`/launches`,
+`/coin-intel`, `/oracle`). The **Markets** surface extends that to the whole
+crypto market: a CoinGecko-style index of the top assets, and a rich,
+shareable detail page for every coin. The design is adopted from the
+[cryptocurrency.cv](https://github.com/nirholas/cryptocurrency.cv) coin pages —
+editorial serif headings, hairline borders, mono numerals, light/dark themes.
+
+## The pages
+
+### `/coins` — markets index
+
+- **Global stats bar** — total market cap (with 24h change), 24h volume, the
+ top-2 dominance shares, the Fear & Greed index, and the active-coin count.
+- **Top coins table** — rank, name, live price, 24h %, 7d %, market cap, 24h
+ volume, and a 7-day sparkline per coin. Every column sorts (click or
+ Enter/Space on a header); every row links to its detail page. "Load more"
+ appends the next 100 ranks.
+- **Search** — a debounced type-ahead over the full CoinGecko catalog with
+ keyboard navigation (↑/↓/Enter/Escape); selecting a result opens its detail
+ page.
+- Responsive: lower-priority columns collapse at small widths, the coin-name
+ column stays sticky while the table scrolls horizontally.
+
+### `/coin/:id` — coin detail
+
+`:id` accepts either a CoinGecko slug or a base58 **Solana mint address**
+(resolved through the contract lookup).
+
+- **Header** — icon, name, symbol, market-cap-rank badge, live price, and
+ 24h / 7d / 30d change chips, plus the coin's categories.
+- **Interactive chart** — SVG line chart across 24H / 7D / 30D / 90D / 1Y with
+ a crosshair tooltip showing exact price and time.
+- **Market stats** — market cap, 24h volume, circulating/total supply,
+ all-time high and low (dated), 24h high/low.
+- **Related news** — live articles mentioning the coin, from the
+ cryptocurrency.cv aggregator with a direct-RSS fallback.
+- **About + links** — plain-text description, official site / social /
+ explorer pills, and per-chain contract addresses with one-click copy.
+- **three.ws integration** — coins with a Solana contract cross-link into
+ [Alpha Copilot](/alpha-copilot) and the [live trade feed](/trades). A
+ mint-shaped id that isn't on the market data source points to its
+ [launch profile](/launches) and [Coin Intelligence](/coin-intel) instead.
+
+Unknown ids, upstream outages, loading, and empty news all have designed
+states — the page never renders a blank void.
+
+## Where the data comes from
+
+All data is real and fetched at runtime — nothing is hardcoded or sampled:
+
+| Endpoint | Upstream | Cache |
+|---|---|---|
+| `/api/coin/detail` | CoinGecko `/coins/{id}` or `/coins/solana/contract/{mint}` | 60 s |
+| `/api/coin/ohlc` | CoinGecko `/coins/{id}/market_chart` | 120 s |
+| `/api/coin/markets` | CoinGecko `/coins/markets`, `/search` | 60 s / 300 s |
+| `/api/coin/global` | CoinGecko `/global` + alternative.me Fear & Greed | 120 s |
+| `/api/coin/news` | cryptocurrency.cv aggregator → first-party RSS fallback | 300 s |
+
+Full request/response shapes: [api-reference.md → Coin Market Data API](api-reference.md#coin-market-data-api).
+
+The proxies live in [`api/coin/`](../api/coin) over the shared
+[`api/_lib/coingecko.js`](../api/_lib/coingecko.js) fetcher (optional
+`COINGECKO_API_KEY` env lifts the public rate limit; everything works
+key-free). Payloads are slimmed server-side — the markets endpoint downsamples
+sparklines so 100 rows stay light, and coin descriptions are stripped to plain
+text before they reach the client.
+
+## Code map
+
+| Piece | Location |
+|---|---|
+| Markets page | [`pages/coins.html`](../pages/coins.html) + [`src/coins-index.js`](../src/coins-index.js) |
+| Detail page | [`pages/coin.html`](../pages/coin.html) + [`src/coin-page.js`](../src/coin-page.js) |
+| 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`, `news.js` |
+
+Routing: `vercel.json` rewrites `/coins` and `/coin/<id>` to the two pages in
+production; the Vite dev server mirrors both (including the dynamic
+`/coin/:id` path). The pre-existing `/coin` (no id) redirect to `/demo/coin`
+is untouched.