Set monthly granulary for fx rates

This commit is contained in:
natsoni
2024-03-11 15:27:43 +01:00
parent 8e158e1786
commit 669cf59269
3 changed files with 49 additions and 39 deletions

View File

@@ -329,24 +329,18 @@ class PricesRepository {
throw Error(`Cannot get single historical price from the database`);
}
let pricesUsedForExchangeRates; // If we don't have a fx API key, we need to use the latest prices to compute the exchange rates
if (!config.FIAT_PRICE.API_KEY) {
const [latestPrices] = await DB.query(`
SELECT ${ApiPriceFields}
FROM prices
ORDER BY time DESC
LIMIT 1
`);
if (!Array.isArray(latestPrices)) {
throw Error(`Cannot get single historical price from the database`);
}
pricesUsedForExchangeRates = latestPrices[0] as ApiPrice;
} else {
pricesUsedForExchangeRates = rates[0] as ApiPrice;
}
const [latestPrices] = await DB.query(`
SELECT ${ApiPriceFields}
FROM prices
ORDER BY time DESC
LIMIT 1
`);
if (!Array.isArray(latestPrices)) {
throw Error(`Cannot get single historical price from the database`);
}
// Compute fiat exchange rates
let latestPrice = pricesUsedForExchangeRates;
let latestPrice = latestPrices[0] as ApiPrice;
if (!latestPrice || latestPrice.USD === -1) {
latestPrice = priceUpdater.getEmptyPricesObj();
}