javascript——我想找出硬币价格的最大变化率

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

我想在我的硬币数据中找到最大的价格变化率
比如,如果sdt oldprice是1.00,新价格是1.02=2%,如果它是硬币中最大的变化率,我的脚本应该打印它
但是剧本不起作用,只会继续给我同样的硬币

const math = require('mathjs');
const fetch = require('node-fetch');
get()
async function get() {
  const response = await fetch("https://trade.kucoin.com/_api/currency/prices?base=USD&targets=&lang=en_US");
  const coin1 = await response.json();
  const olddata = coin1.data
  const tokens = Object.keys(olddata)
  const oldprice = Object.values(olddata)
  get1()
  async function get1() {
    const response = await fetch("https://trade.kucoin.com/_api/currency/prices?base=USD&targets=&lang=en_US");
    const coin2 = await response.json();
    const newdata = coin2.data
    const tokens = Object.keys(newdata)
    const newprice = Object.values(newdata)
    function findLargestDifference() {
      var large = null;
      var index = 0;
      for (var i = 0; i < oldprice.length; i++) {
        var change = tokens[i].newprice / oldprice[i].oldprice;
        if (change > large) {
          large = change;
          index = i;
        }
      }
      console.log(tokens[index])
      return tokens[index];
    }
    findLargestDifference()
  }
}

下面是数据的外观https://prnt.sc/19syjjg

暂无答案!

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

相关问题