Skip to content

feat: add GET /spreads/:asset route to calculate bid-ask spreads for …#95

Open
Johnsource-hub wants to merge 1 commit into
Miracle656:mainfrom
Johnsource-hub:spreads-endpoint
Open

feat: add GET /spreads/:asset route to calculate bid-ask spreads for …#95
Johnsource-hub wants to merge 1 commit into
Miracle656:mainfrom
Johnsource-hub:spreads-endpoint

Conversation

@Johnsource-hub

Copy link
Copy Markdown

#closes
#93

New route added and registered.
Basic error handling implemented.
Documentation and inline comments included.
Tests (to be added) cover functionality.
No new dependencies introduced.

@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@Johnsource-hub 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.

Thanks for tackling #93 — the route skeleton is a good start, but a few things need fixing before it can merge:

1. The bid/ask are inverted (correctness bug). Right now bid = MAX(price) and ask = MIN(price), so bid ≥ ask always, which makes spreadBps = ((ask - bid) / ask) * 10000 always negative. A bid-ask spread needs ask ≥ bid. Also, taking max/min over all historical trade prices isn't a bid-ask spread — that's a price range. A real spread needs quote/order-book data (best bid vs best ask) or, if you only have trade points, it should be defined and named accordingly. Please rework the calculation so it returns a meaningful, non-negative spread.

2. It isn't actually registered. src/index.ts wires up routes via registerRESTRoutes/registerPriceRoutes/registerCandleRoutes/etc., but there's no registerSpreadsRoutes(app) call (and no import). As-is the endpoint is unreachable — please add the import + await registerSpreadsRoutes(app) alongside the others.

3. Check the SQL column names. Unquoted assetA = $1 OR assetB = $1 folds to asseta/assetb in Postgres and won't match the actual columns. Look at how the other raw queries reference price_points and match that exactly (quote the identifier if the column is camelCase).

4. Add the test. The checklist notes tests are still to be added — please include at least one covering a normal spread and the empty/no-data case.

Once the spread math is correct, the route is registered, and there's a test, this is good to go. 👍

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.

2 participants