Query 24h fees
In order to get the 24h fees earned by RenVM, you'll need to fetch the current all-time fees, and the all-time fees from 24 hours ago, and subtract the two.
const currentTimestamp = Math.floor(Date.now() / 1000);
> 1628130330
const previousTimestamp = currentTimestamp - (24 * 60 * 60)
> 1628043930
You can then loop each asset to get the difference:
// Get the fees collected as of 24 hours ago
const dayAgo = response.data.dayAgo.fees.reduce(
(acc, fees) => ({ ...acc, [fees.asset]: fees.amount }),
{}
);
// Get the current fees collected
const current = response.data.current.fees.reduce(
(acc, fees) => ({ ...acc, [fees.asset]: fees.amount }),
{}
);
// Get the latest prices
const prices = response.data.current.prices.reduce(
(acc, prices) => ({ ...acc, [prices.asset]: prices }),
{}
);
const assets = Object.keys(current);
// Sum up the difference for each asset, converted to USD.
const oneDayFees = assets.reduce((acc, asset) => {
const difference = current[asset] - (dayAgo[asset] || 0);
const differentInUsd =
(difference / 10 ** prices[asset].decimals) * prices[asset].priceInUsd;
return acc + (differentInUsd || 0);
}, 0);
// Print the sum in USD, with two decimals.
console.log(oneDayFees.toFixed(2));