-
Notifications
You must be signed in to change notification settings - Fork 127
Description
It'd be nice to display fiat conversions next to values in some places.
- Next to their balance on the wallets page.
- Order quantity on order confirmation form
- Withdraw form
Ideally, we'd have busy stablecoin markets and we could do this without oracles. But in the meantime, we could grab the prices through available public APIs. For Decred and Bitcoin, we can use dcrdata, which already does a weighted average of markets. For others though, we'll need to find new endpoint.
Design considerations
Public APIs will have rate limits and API calls will incur significant delays. We'll need to keep cached values and only update the cache periodically.
On the front-end, we'll need to be flexible, only showing fiat conversion when they're available.
We could implement through the (nah, we should use core, see below), e.g.asset.Wallet
s as an optional interface
type PriceFetcher interface {
FetchPrice(ctx context.Context) (uint64, error)
}
We would have to define a canonical fiat unit, almost certainly USD, and wallets will return values in USD/XYZ
. Or maybe FetchPrice
should take a fiat string
argument.
I could also be a mostly core-level system, which makes more sense if we only rely on one or two APIs for the prices.
Where do we get data for other coins?
We could try to calculate it ourselves. For example, if we know the fiat exchange rate of BTC and DCR, then we can kind of know the exchange rate for any assets that share any markets with those, via a conversion using the mid-gap rate. For example, if we have a BTC-ETH market, then we can get an approximation for ETH by taking ethPriceUSD = btcPriceUSD / midGap
. It won't be the best price, especially if the market is dead. And attempting to chain that logic by, say, figuring the BCH
price from our ETH-BCH
using the aforementioned ETH price would potentially chain and magnify the "error".
I've used coinpaprika before, and as long as you meter your requests, it seems pretty solid.
It looks like messari.io has a non-authenticated API that allows up to 20 requests per minute.