资源加载中... loading...

请教一个JavaScript编程问题

Author: VIC, Created: 2021-03-31 20:37:48, Updated:

大佬们,请教一下 我用 exchange.IO("api", “GET”,"/fapi/v1/ticker/24hr") 获得了24小时永续合约价格变动信息之后,怎样从结果里获得变动价格幅度(priceChangePercent)最大的前几位合约交易对呢? 结果大致下面这样 [{“lastPrice”:“58131.80”,“lowPrice”:“56812.00”,“closeTime”:1617193588048,“lastId”:657590646,“priceChangePercent”:"-1.725",“quoteVolume”:“16870412679.78”,“volume”:“287984.541”,“openTime”:1617107160000,“weightedAvgPrice”:“58580.97”,“lastQty”:“0.004”,“openPrice”:“59152.17”,“highPrice”:“59920.00”,“firstId”:654550517,“count”:3040076,“symbol”:“BTCUSDT”,“priceChange”:"-1020.37"},{“priceChange”:"-30.38",“priceChangePercent”:"-1.648",“closeTime”:1617193587663,“symbol”:“ETHUSDT”,“quoteVolume”:“3758616198.20”,“weightedAvgPrice”:“1829.43”,“lastPrice”:“1813.36”,“highPrice”:“1867.00”,“volume”:“2054532.966”,“lastQty”:“9.445”,“openPrice”:“1843.74”,“lowPrice”:“1771.85”,“openTime”:1617107160000,“firstId”:430017156,“lastId”:431621119,“count”:1603915}…]


More

allez-z function compare(property) { return function(obj1, obj2) { var value1 = obj1[property]; var value2 = obj2[property]; return value2 - value1; // 降序排列 } } function main{ exchange.IO("api", "GET","/fapi/v1/ticker/24hr").sort(compare("priceChangePercent")); } 得到的结果是按照价格变动从大到小排列的

VIC exchange.IO("api", "GET","/fapi/v1/ticker/24hr")返回的好像不是个对象,还是什么问题,报错