feat: implement OHLC aggregation service and fix repository bugs#268
Merged
Sadeequ merged 2 commits intoApr 29, 2026
Conversation
- Added OhlcCandle model to Prisma schema\n- Implemented PriceAggregatorService background worker\n- Added /api/v1/analytics endpoints\n- Fixed numerous bugs (duplications, missing exports, ESM issues)\n- Added comprehensive Jest integration tests
|
@nuhumusamagaji 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the Analytics & OHLC Aggregation Service (Issue #208) to provide pre-aggregated time-series data for charting. It also includes a comprehensive stabilization of the repository, fixing several critical bugs related to duplicated code, ESM compatibility, and broken authentication middleware that were preventing the application from building and testing correctly.
🚀 Key Features
1. OHLC Aggregation Service
OhlcCandlemodel with a composite unique constraint on[currency, granularity, openTime]to ensure data integrity.PriceAggregatorService, a robust worker that calculatesMINUTE,HOUR, andDAYcandles from rawPriceHistoryticks.LOOKBACK_WINDOWS) to capture late-arriving data and ensure no gaps in the charts.upsertoperations to handle retries and overlapping runs without duplicating data.2. Analytics API Endpoints
/api/v1/analytics/ohlc: Efficiently retrieves aggregated candles with support for currency filtering, granularity selection, and time-range queries./api/v1/analytics/status: Provides real-time visibility into the health and status of the aggregation worker.3. Repository Stabilization & Bug Fixes
src/routes/marketRates.tsandsrc/middleware/apiKeyMiddleware.ts.apiKeyAuthmiddleware, resolving503 Service Unavailableerrors by properly integrating with the shared Prisma instance.__dirnameusage insrc/utils/winstonLogger.tsfor ESM compatibility.src/services/webhook.tsand missing imports insrc/services/marketRate/marketRateService.ts.Horizonanddefault exportdeclarations instellarProvider.ts.postgresqlto match the application's native type requirements.🧪 Testing & Verification
test/priceAggregator.jest.test.tscovering:🛠 How to Test
npx prisma generateto update the local client.DATABASE_URLis set to a PostgreSQL instance.npm run test:jest(ornode --experimental-vm-modules ./node_modules/jest/bin/jest.js test/priceAggregator.jest.test.ts).GET http://localhost:PORT/api/v1/analytics/ohlc?currency=NGN&granularity=HOUR📦 Dependencies Added/Updated
@prisma/client,express, and@stellar/stellar-sdk).Closes: #208