Page MenuHomePhabricator

[herald] add function to get crypto price info
ClosedPublic

Authored by bytesofman on Apr 5 2023, 16:38.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABCdd4c0e446e81: [herald] add function to get crypto price info
Summary

T2972

Depends on D13584

Add new function to make configurable API call to coingecko for fiat price information

Include unit tests for mock responses and a new script, npm run getPrices, to test the function with a real API call

Test Plan

npm i
npm test
npm run getPrices and expected price info is logged to console

Diff Detail

Repository
rABC Bitcoin ABC
Branch
tg-bot-price-fetch
Lint
Lint Errors
SeverityLocationCodeMessage
Errorapps/ecash-herald/scripts/getCoingeckoPrices.js:2ESLINTno-unused-vars
Errorapps/ecash-herald/scripts/getCoingeckoPrices.js:23ESLINTno-undef
Unit
No Test Coverage
Build Status
Buildable 23009
Build 45638: Build Diffecash-herald-tests
Build 45637: arc lint + arc unit

Event Timeline

Fabien added inline comments.
apps/ecash-herald/scripts/getPrices.js
9 ↗(On Diff #39305)

no ecash here ?

apps/ecash-herald/src/utils.js
38 ↗(On Diff #39305)

This is making the getPrices call dependent of the backend price provider. I you want to implement a fallback, that will be a problem.
You should rather have an abstract interface for requesting the price and an implementation of that interface that actually does the glue with coingecko. That also means that you can create several instances of that interface and facilitate the implementation of a fallback.

add ecash to examples, change function name to getCoingeckoPrices

bytesofman added inline comments.
apps/ecash-herald/src/utils.js
38 ↗(On Diff #39305)

renamed the function to getCoingeckoPrices

Another price API would probably have have its own formatting and url intricacies to deal with. imo more robust to add a fallback as a distinct function if we decide to add one. That way, if getCoingeckoPrices returns false, the app can try something else like getCoinmarketcapPrices. Or not.

Most likely there will not be a fallback implemented, but if there is, this should be dealt with at that time.

For the first implementation, the app simply will not render the price if coinGeckoPrices is false, which is acceptable behavior for the telegram bot. (to be next diff)

This revision is now accepted and ready to land.Apr 5 2023, 19:05
This revision was automatically updated to reflect the committed changes.
bytesofman marked an inline comment as done.