计算431令牌的百分比变化,并找到更大的变化

hyrbngr7  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(139)

我的代币价格数据中的示例chz是价格的较大变化百分比
就像旧价格是0.10,新价格是0.12=20%的变化
但是计算百分比变化的问题在我的代码中不起作用,因为我想计算431个代币的价格,以便在代币中找到更大的价格变化率并打印代币名称
其他例子

MLK oldprice = 2.3
XTZ oldprice = 4.10
ADA oldprice = 1.0

MLK newprice = 2.45
XTZ newprice = 4.30
ADA newprice = 1.12

你可以看到ada的变化率更大
我的脚本应该打印(“ada 12%”)
需要帮忙吗谢谢

const qs = require('querystring');
const fetch = require('node-fetch');
fetch('https://openapi-v2.kucoin.com/api/v1/prices') //Request to get oldprices and tokens name
    .then(res => res.json())
    .then(olddata => {
        const token = (Object.keys(olddata.data)); //tokens names
        const oldprice = (Object.values(olddata.data)); //oldprice for compare with newprice
fetch('https://openapi-v2.kucoin.com/api/v1/prices') //Request to get newprices
    .then(res => res.json())
    .then(newdata => {
        const token = (Object.keys(newdata.data)); //tokens names
        const newprice = (Object.values(newdata.data)); //newprice for compare with oldprice
        const change = (newprice - oldprice); //not worked 
        const percentageChange = 100 * change / oldprice;
});
    })

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题