FIX: change faulty exchange rate API

This commit is contained in:
overtorment 2023-01-28 12:45:35 +00:00
parent 49dcf04b8d
commit 38a8a02459
2 changed files with 26 additions and 4 deletions

View file

@ -6,6 +6,7 @@ export const FiatUnitSource = {
YadioConvert: 'YadioConvert',
Exir: 'Exir',
wazirx: 'wazirx',
Bitstamp: 'Bitstamp',
} as const;
const RateExtractors = {
@ -25,6 +26,27 @@ const RateExtractors = {
return rate;
},
Bitstamp: async (ticker: string): Promise<number> => {
let json;
try {
const res = await fetch(`https://www.bitstamp.net/api/v2/ticker/btc${ticker.toLowerCase()}`);
json = await res.json();
} catch (e: any) {
throw new Error(`Could not update rate from Bitstamp for ${ticker}: ${e.message}`);
}
if (Array.isArray(json)) {
throw new Error(`Unsupported ticker for Bitstamp: ${ticker}`);
}
let rate = +json?.last;
if (!rate) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
rate = Number(rate);
if (!(rate >= 0)) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
return rate;
},
Yadio: async (ticker: string): Promise<number> => {
let json;
try {
@ -95,7 +117,7 @@ type FiatUnit = {
endPointKey: string;
symbol: string;
locale: string;
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx';
source: 'CoinDesk' | 'Yadio' | 'Exir' | 'wazirx' | 'Bitstamp';
};
};
export const FiatUnit = untypedFiatUnit as FiatUnit;

View file

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