我正在开发自己的应用,我希望在24小时内检索价格数据。我已阅读Binance在https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
提供的文档然后,我尝试使用链接https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT获取 24小时自动收报机价格变动统计信息。答复是:
{
"symbol": "BTCUSDT",
"priceChange": "111.60000000",
"priceChangePercent": "1.314",
"weightedAvgPrice": "8563.97044287",
"prevClosePrice": "8491.29000000",
"lastPrice": "8604.60000000",
"lastQty": "0.40675900",
"bidPrice": "8602.69000000",
"bidQty": "0.02000000",
"askPrice": "8610.79000000",
"askQty": "0.13200000",
"openPrice": "8493.00000000",
"highPrice": "8763.36000000",
"lowPrice": "8298.00000000",
"volume": "26054.86683400",
"quoteVolume": "223133109.45927182",
"openTime": 1526170656448,
"closeTime": 1526257056448,
"firstId": 42721797,
"lastId": 42939912,
"count": 218116
}
但是当我尝试使用以下链接加载 Kline / Candlestick数据时:https://api.binance.com/api/v1/klines?symbol=BNBBTC&interval=15m&startTime=1526170656448&endTime=1526257056448( startTime 和 endTime 设置与上面的响应中的 openTime 和 closeTime 完全相同。结果是:
[
[
1526171400000, // Open time
"0.00154030", // Open
"0.00154560", // High
"0.00153600", // Low
"0.00153780", // Close
"5716.55000000", // Volume
1526172299999, // Close time
"8.79961911", // Quote asset volume
729, // Number of trades
"2149.12000000", // Taker buy base asset volume
"3.30996242", // Taker buy quote asset volume
"0" // Ignore
],
.......
[
1526256900000,
"0.00150450",
"0.00150680",
"0.00150430",
"0.00150590",
"985.40000000",
1526257799999,
"1.48381883",
198,
"508.80000000",
"0.76612330",
"0"
]
就价格变动百分比而言,我尝试使用最后一个区间的收盘价和第一个区间的开盘价(0.00150590 / 0.00154030)进行计算 - 1 = -2.2%),但结果-2.2%完全不同于" priceChangePercent":" 1.314"在24小时的股票价格变动统计数据中。
我的问题,Binance API如何计算24小时内与Kline / Candlestick数据相关的价格变化百分比?谢谢你为你的时间做了很多。
答案 0 :(得分:1)
不,是:
priceChangePercent = (lastPrice - openPrice)/(openPrice)
如果 lastPrice 大于 openprice (openPrice - lastPrice)/(openPrice) 会给你一个负百分比!
答案 1 :(得分:0)
priceChangePercent由
计算获取(openPrice-lastPrice)/(openPrice)
希望有帮助!