Binance API如何在24小时内计算priceChangePercent [英] How do Binance API calculate priceChangePercent in 24h

查看:131
本文介绍了Binance API如何在24小时内计算priceChangePercent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发自己的应用程序,希望在24小时内检索价格数据.我已经在 https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

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

然后,我尝试使用链接24小时行情价格变化统计.rel ="nofollow noreferrer"> https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT .响应为:

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
}

但是当我尝试使用此链接加载 Kline/烛台数据时:

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

就价格变化百分比而言,我尝试使用最后一个区间的收盘价第一个区间的开盘价进行计算(0.00150590/0.00154030-1 = -2.2%),但结果-2.2%与24小时报价器价格变化统计信息中的"priceChangePercent":"1.314"完全不同.

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.

我的问题是,Binance API如何计算24小时内与Kline/烛台数据有关的价格变化百分比?谢谢您的宝贵时间.

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.

推荐答案

不,是:

priceChangePercent = (lastPrice-openPrice)/(openPrice)

priceChangePercent = (lastPrice - openPrice )/(openPrice)

如果lastPrice大于openprice(openPrice-lastPrice)/(openPrice)会给您一个负百分比!

If lastPrice is bigger than openprice (openPrice - lastPrice)/(openPrice) would give you a negative percentage !

这篇关于Binance API如何在24小时内计算priceChangePercent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆