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

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

问题描述

我正在开发自己的应用程序,我想在其中检索 24 小时内的价格数据.我已在 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.回复是:

<代码>{"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","音量": "26054.86683400","quoteVolume": "223133109.45927182",开放时间":1526170656448,关闭时间":1526257056448,firstId":42721797,lastId":42939912,计数":218116}

但是当我尝试使用以下链接加载 Kline/Candlestick 数据时:https://api.binance.com/api/v1/klines?symbol=BNBBTC&interval=15m&startTime7056448/a>(将 startTimeendTime 设置为与响应中的 openTimecloseTime 完全相同以上).结果是:

<预><代码>[[1526171400000,//打开时间"0.00154030",//打开"0.00154560",//高"0.00153600",//低"0.00153780",//关闭"5716.55000000",//成交量1526172299999,//关闭时间"8.79961911",//报价资产量729,//交易次数"2149.12000000",//Taker 买入基础资产量"3.30996242",//Taker 买入报价资产量"0"//忽略],......[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" 完全不同.

我的问题是,币安 API 如何计算与 Kline/Candlestick 数据相关的 24 小时内的价格变化百分比?非常感谢您抽出宝贵时间.

解决方案

不,是:

priceChangePercent = (lastPrice - openPrice)/(openPrice)

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

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.

解决方案

No, it's:

priceChangePercent = (lastPrice - openPrice )/(openPrice)

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

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

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