feat: add OpenAPI spec, price confidence scores and rate limiting - #46
Conversation
|
@Viv-90 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Miracle656
left a comment
There was a problem hiding this comment.
Great work closing three issues in one PR — the OpenAPI spec is well-structured, the confidence scoring algorithm is reasonable, and the rate-limit tiers (100/min public, 1000/min for /status) make sense. One required fix:
node_modules/.package-lock.json must not be committed
Your diff includes changes to node_modules/.package-lock.json (1617 lines). The node_modules/ directory should be in .gitignore — this file should never appear in a PR. Remove it from your branch:
git rm -r --cached node_modules
git commit -m 'chore: untrack node_modules'
Then push and I'll merge immediately.
|
Hi @Miracle656, I've ignored the node_modules/ directory in .gitignore |
…ng (#46) - Add openapi.yaml covering all 5 main price/candle/aggregate endpoints - Add confidence field (high/medium/low/unknown) to price responses based on lastTradeAgeSeconds, source count, and 24h volume - Add @fastify/rate-limit: 100 req/min global, /status effectively unlimited - Add lastTradeAgeSeconds to price response type and aggregator output - Add 4 Vitest tests covering all confidence levels
|
Merged into main via squash commit 20c5bbc — thanks Viv-90! The OpenAPI spec, confidence scores, and rate limiting are all live on the main branch. |
1 similar comment
|
Merged into main via squash commit 20c5bbc — thanks Viv-90! The OpenAPI spec, confidence scores, and rate limiting are all live on the main branch. |
Summary
This PR addresses three key infrastructure and feature requests for the Lens API: generating an OpenAPI specification, adding price confidence metrics and implementing rate limiting middleware
Type of change
Changes
OpenAPI 3.0 Specification
Created openapi.yaml documenting all REST endpoints (/status, /price, /pools, /candles, /pairs).
Included x402 payment header as a security requirement.
Added a link to the specification in README.md.
Validated the spec with Redocly.
Closes Generate OpenAPI spec for Lens REST endpoints #22
Price Confidence Score
Added confidence ('high' | 'medium' | 'low' | 'unknown') and lastTradeAgeSeconds to the /price response.
Implemented a confidence algorithm in src/aggregator/vwap.ts based on trade recency, volume, and number of sources.
Updated REST and GraphQL schemas to include these new fields.
Added unit tests in src/tests/price.test.ts covering all confidence levels.
Closes Add price confidence score to /price response #28
Rate Limiting Middleware
Added @fastify/rate-limit to the server.
Applied a 100 req/min global limit for unauthenticated endpoints.
Set a higher limit (1000 req/min) for /status to accommodate monitoring tools.
Configured the API to return 429 Too Many Requests with Retry-After and X-RateLimit-Remaining headers.
Closes Add rate limiting middleware #32
Verification Results
Automated Tests: All 44 tests passed (npm test).
OpenAPI Linting: Spec is valid according to redocly lint.
Manual Check: Verified confidence scores and rate limit headers are correctly present in API responses.