Skip to content

feat: add OpenAPI spec, price confidence scores and rate limiting - #46

Merged
Miracle656 merged 4 commits into
Miracle656:mainfrom
Viv-90:main
Apr 28, 2026
Merged

feat: add OpenAPI spec, price confidence scores and rate limiting#46
Miracle656 merged 4 commits into
Miracle656:mainfrom
Viv-90:main

Conversation

@Viv-90

@Viv-90 Viv-90 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

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

  • Bug fix
  • New feature
  • Refactor
  • Docs
  • Tests
  • CI / tooling

Changes

  1. 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

  2. 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

  3. 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.

@drips-wave

drips-wave Bot commented Apr 25, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@Miracle656 Miracle656 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Viv-90

Viv-90 commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Miracle656, I've ignored the node_modules/ directory in .gitignore

Miracle656 added a commit that referenced this pull request Apr 27, 2026
…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
@Viv-90
Viv-90 requested a review from Miracle656 April 27, 2026 22:11
@Salmatcre8

Copy link
Copy Markdown
Contributor

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
@Salmatcre8

Copy link
Copy Markdown
Contributor

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.

@Miracle656

Copy link
Copy Markdown
Owner

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.

@Miracle656 Miracle656 closed this Apr 28, 2026
Miracle656 pushed a commit that referenced this pull request Apr 28, 2026
@Miracle656 Miracle656 reopened this Apr 28, 2026
@Miracle656
Miracle656 merged commit 7bdb105 into Miracle656:main Apr 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add rate limiting middleware Add price confidence score to /price response Generate OpenAPI spec for Lens REST endpoints

3 participants