-
Notifications
You must be signed in to change notification settings - Fork 23
fix fetch token price to Binance API #522
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the proposed solution does eliminate console errors, it does so by swallowing errors and requests from the different price feeds asymmetrically. So when we do see the rate limit errors (which we will) we will only ever see the BinanceAPI error.
I think this problem could be addressed more appropriately with some basic caching. Our servicies shouldn't be requesting the price of near more than once every minute or two. I would propose using something like https://www.npmjs.com/package/cache-manager with an expiry of 120 seconds.
Oh - I just realized that this is mintbase-js. The caching should be done on the application layer.
|
@bh2smith you already answered yourself. Binance doesnt have rate limit, as I said on desc. Coingecko has. |
| let res: NearPriceData; | ||
| try { | ||
| res = await fetchPrice<CoinGeckoNearPriceData>(COIN_GECKO_API, data => ({ price: data.near.usd })); | ||
| } catch (err) { | ||
| res = await fetchPrice<NearPriceData>(BINANCE_API, data => data); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are prioritizing CoinGecko by calling it first and swallowing their errors.
These two APIS are different. Just keep the Promise.any, catch rate limit errors and handle them differently (like return null).
Have you considered adding another API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered adding another API?
https://coinmarketcap.com/api/pricing/
https://coinpaprika.com/api/
this is something I needed to do later, user can pass it api and we fetch for him.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

promise.any calls both apis at same type and coingecko has ratelimits that make it call many times with error.. Binance always give 200.