diff --git a/models/fiatUnit.ts b/models/fiatUnit.ts index f9f157a2f..ddcb746ee 100644 --- a/models/fiatUnit.ts +++ b/models/fiatUnit.ts @@ -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 => { + try { + const response = await fetch('https://www.bnr.ro/nbrfxrates.xml'); + const xmlData = await response.text(); + const targetCurrency = 'USD'; + + const pattern = new RegExp(`([\\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 => { let json; try { diff --git a/models/fiatUnits.json b/models/fiatUnits.json index 6a1c0d7f5..7adc7d577 100644 --- a/models/fiatUnits.json +++ b/models/fiatUnits.json @@ -245,6 +245,12 @@ "source": "CoinDesk", "symbol": "ر.ق." }, + "RON": { + "endPointKey": "RON", + "locale": "ro-RO", + "source": "BNR", + "symbol": "lei" + }, "RUB": { "endPointKey": "RUB", "locale": "ru-RU",