Last active
April 6, 2022 16:45
-
-
Save luan0ap/58ad674a8bb734a9d44fecf71dac7c8d to your computer and use it in GitHub Desktop.
Calculate cryptocurrency average price from Binance API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cryptoAveragePrice(binanceData) { | |
return binanceData.reduce((sum, { totalQuota, price }) => { | |
const totalBought = sum.totalBought + Number(totalQuota) | |
const totalPrice = sum.totalPrice + Number(totalQuota) * Number(price) | |
return { | |
totalBought, | |
totalPrice, | |
average: totalPrice / totalBought | |
} | |
}, { totalBought: 0, totalPrice: 0, average: 0 }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment