Merge pull request #6604 from BlueWallet/fix-exchange-rate

FIX: use exchange rate for USD, GBP & EUR from Kraken public API
This commit is contained in:
GLaDOS 2024-05-24 18:27:47 +00:00 committed by GitHub
commit 0fc46bbb2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View File

@ -4,6 +4,7 @@ export const FiatUnitSource = {
Coinbase: 'Coinbase',
CoinDesk: 'CoinDesk',
CoinGecko: 'CoinGecko',
Kraken: 'Kraken',
Yadio: 'Yadio',
YadioConvert: 'YadioConvert',
Exir: 'Exir',
@ -75,6 +76,23 @@ const RateExtractors = {
if (!(rate >= 0)) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
return rate;
},
Kraken: async (ticker: string): Promise<number> => {
let json;
try {
const res = await fetch(`https://api.kraken.com/0/public/Ticker?pair=XXBTZ${ticker.toUpperCase()}`);
json = await res.json();
} catch (e: any) {
throw new Error(`Could not update rate from Kraken for ${ticker}: ${e.message}`);
}
let rate = json?.result?.[`XXBTZ${ticker.toUpperCase()}`]?.c?.[0];
if (!rate) throw new Error(`Could not update rate from Kraken for ${ticker}: data is wrong`);
rate = Number(rate);
if (!(rate >= 0)) throw new Error(`Could not update rate from Kraken for ${ticker}: data is wrong`);
return rate;
},
BNR: async (): Promise<number> => {
try {
const response = await fetch('https://www.bnr.ro/nbrfxrates.xml');
@ -168,7 +186,7 @@ export type TFiatUnit = {
endPointKey: string;
symbol: string;
locale: string;
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp';
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp' | 'Kraken';
};
export type TFiatUnits = {

View File

@ -2,7 +2,7 @@
"USD": {
"endPointKey": "USD",
"locale": "en-US",
"source": "CoinGecko",
"source": "Kraken",
"symbol": "$"
},
"AED": {
@ -92,13 +92,13 @@
"EUR": {
"endPointKey": "EUR",
"locale": "en-IE",
"source": "CoinGecko",
"source": "Kraken",
"symbol": "€"
},
"GBP": {
"endPointKey": "GBP",
"locale": "en-GB",
"source": "CoinGecko",
"source": "Kraken",
"symbol": "£"
},
"HRK": {