This commit is contained in:
Marcos Rodriguez Velez 2023-10-26 08:44:35 -04:00
parent 1e5048a4a7
commit 881b20a802
No known key found for this signature in database
GPG key ID: 6030B2F48CCE86D7
2 changed files with 30 additions and 0 deletions

View file

@ -9,6 +9,7 @@ export const FiatUnitSource = {
Exir: 'Exir',
wazirx: 'wazirx',
Bitstamp: 'Bitstamp',
BNR: 'BNR',
} as const;
const RateExtractors = {
@ -74,7 +75,30 @@ const RateExtractors = {
if (!(rate >= 0)) throw new Error(`Could not update rate from Bitstamp for ${ticker}: data is wrong`);
return rate;
},
BNR: async (): Promise<number> => {
try {
const response = await fetch('https://www.bnr.ro/nbrfxrates.xml');
const xmlData = await response.text();
const targetCurrency = 'USD';
const pattern = new RegExp(`<Rate currency="${targetCurrency}">([\\d.]+)<\\/Rate>`);
const matches = xmlData.match(pattern);
if (matches && matches[1]) {
const ronExchangeRate = parseFloat(matches[1]);
if (!isNaN(ronExchangeRate) && ronExchangeRate > 0) {
return ronExchangeRate;
}
}
throw new Error(`Could not find a valid exchange rate for ${targetCurrency}`);
} catch (error: any) {
throw new Error(`Could not fetch RON exchange rate: ${error.message}`);
}
},
Yadio: async (ticker: string): Promise<number> => {
let json;
try {

View file

@ -245,6 +245,12 @@
"source": "CoinDesk",
"symbol": "ر.ق."
},
"RON": {
"endPointKey": "RON",
"locale": "ro-RO",
"source": "BNR",
"symbol": "lei"
},
"RUB": {
"endPointKey": "RUB",
"locale": "ru-RU",