← back to Rentv Website

MARKETS-PATCH.md

52 lines

# Rates & Markets — additive patch (fold into the rentv-v1 ↔ rentv-website parity baseline)

**Why this file exists:** a live **Rates & Markets** dashboard (`/markets.html`) was built, but the
`/api/markets` route kept getting clobbered by the force-parity syncs between `rentv-v1` and
`rentv-website`. To make it durable, please fold the two shared-file edits below into **whichever
project is the parity source of truth**, so it survives the next sync. The two *new files* already
ship in the repo — only the 2 small shared-file additions get lost on sync.

Live data source: **Yahoo Finance** (free, no key) — CBOE Treasury yields + Dow Jones/MSCI REIT indices.
Nothing here touches `ticker.json` / `pull-ticker.mjs` / `index.html` / the reader flow.

---

## 1. New files (already in repo — verify present in BOTH projects)
- `public/markets.html` — the dashboard page (Treasury curve, curve spreads, REIT benchmarks, CRE
  fundamentals). Standalone; fetches `/api/markets`. Its top nav is a plain bar — align it to the
  hamburger nav if you want parity, but it's not required to function.
- `scripts/pull-markets.mjs` — standalone live-data generator; writes `data/markets.json`. Additive,
  does not import or modify `pull-ticker`.

## 2. `server.js` — add the `/api/markets` route (right after the `/api/ticker` route)
```js
// ── Rates & Markets dashboard data (Treasury curve + REIT indices, live via Yahoo) ──
app.get('/api/markets', (_q, r) => {
  r.set('Cache-Control', 'public, max-age=120');
  r.json(readJSON('markets.json', {}));
});
```

## 3. `scripts/pull-news.mjs` — refresh markets on the same cron (add after the pull-ticker import)
Find the existing line near the end:
```js
try { await import('./pull-ticker.mjs'); } catch (e) { console.error('ticker refresh failed:', e.message); }
```
Add immediately after it:
```js
try { await import('./pull-markets.mjs'); } catch (e) { console.error('markets refresh failed:', e.message); }
```

---

## Verify (per project)
```sh
node scripts/pull-markets.mjs                    # → "markets.json written | 7/7 live symbols"
# after server restart / deploy:
curl -s -u admin:'DW2024!' http://localhost:<port>/api/markets | jq '.curve|length'   # → 4
# public: https://rentv-website.agentabrams.com/markets.html should render the 4 curve cards
```

Nav link (optional): add `<a href="/markets.html">Rates &amp; Markets</a>` to the header nav in
`index.html` once the reader work settles.