How do Binance API calculate priceChangePercent in 24h

痞子三分冷 提交于 2020-05-15 10:27:06

问题


I am developing my own app in which I want to retrieve price data in a 24h period. I have read the docs provided by Binance at https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

Then I try fetching 24hr ticker price change statistics by using the link https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT. The response is:

{
  "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
}

But when I try loading Kline/Candlestick data by using this link: https://api.binance.com/api/v1/klines?symbol=BNBBTC&interval=15m&startTime=1526170656448&endTime=1526257056448 (which has startTime and endTime set to be exactly the same as openTime and closeTime in the response above). And the result is:

[
  [
    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"
  ]

As far as price change percentage is concerned, I have try calculating using the close price of the last interval and the open price of the first interval (0.00150590 / 0.00154030 - 1 = -2.2%), but the result -2.2% is completely different from "priceChangePercent": "1.314" in the 24hr ticker price change statistics.

My question, how do Binance API calculate price change percentage in a 24h period pertaining to Kline/Candlestick data? Thank you do much for your time.


回答1:


priceChangePercent is computed by

taking (openPrice - lastPrice)/(openPrice)

hope that helped!



来源:https://stackoverflow.com/questions/50321891/how-do-binance-api-calculate-pricechangepercent-in-24h

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!