IndexSwapy API
A serverless API on Netlify Functions that serves conversion ratios between QQQ, NDX, NQ, ES and SPY and converts values between them. It backs the IndexSwapy frontend.
Features
- Scrapes current NDX/QQQ, NQ/QQQ and ES/SPY ratios from a public converter page and caches them for 15 minutes (falls back to the last good values if a fetch fails)
GETendpoints that return the current ratiosPOSTconversion endpoint: QQQ to/from NDX, QQQ to/from NQ, ES to/from SPY- Input validation (JSON only, 4 KB body limit, value range checks, ratio sanity bounds)
- Per-IP rate limiting (60 requests per minute)
- CORS restricted to the production frontend and localhost; security headers on every response
Tech stack
- Node.js, Netlify Functions
- axios and cheerio for scraping
Getting started
Prerequisites: Node.js and npm.
npm install
npm start # local server at http://127.0.0.1:8888
npm test # run test/test-api.jsNo environment variables are required.
API
Base path in production is /.netlify/functions/indexswapy; netlify.toml also rewrites /api/*, /ratios, /data and /* to the function.
| Method | Path | Description |
|---|---|---|
| GET | / | Status, ratios and list of endpoints |
| GET | /ratios, /api/ratios, /data | Current ratios |
| POST | any path | Convert a value. Body: { "type": "<conversion>", "value": <number> } |
Conversion types: qqq_to_ndx, ndx_to_qqq, qqq_to_nq, nq_to_qqq, es_to_spy, spy_to_es. Values must be between 0 and 1,000,000.
Ratio response:
{
"status": "ok",
"timestamp": "2025-04-14T12:58:30.153Z",
"ratios": {
"NDX/QQQ Ratio": 41.10241216829076,
"NQ/QQQ Ratio": 41.29471200210854,
"ES/SPY Ratio": 10.072138887159946
}
}Conversion response: { "status": "ok", "result": 20550.12 }.
Errors return { "status": "error", "message": "..." } with 400, 404, 405, 413, 415, 429 or 503.
Deployment
Deploy to Netlify. netlify.toml sets the functions directory to functions, adds the rewrites above and sets security headers. There is no build command.
Project structure
functions/indexswapy.js The Netlify function (scraping, caching, routing, conversions)
test-server.js Local HTTP wrapper around the handler
test/test-api.js Tests
netlify.toml Netlify build, headers and redirectsStatus
Maintained (dependency updates in 2026).