jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.57k stars 767 forks source link

futuresChart returns inaccurate data #872

Closed Eluvade closed 2 months ago

Eluvade commented 1 year ago

I noticed an inaccuracy in the candlesticks(ohlcv) data that futuresChart returns.

For example, I'm subscribed to the daily chart of BTCUSDT perpetual futures market. If I fetch/curl the data directly from Binance I get: [1675728000000,"22757.80","23368.60","22742.40","23234.10","447273.494",1675814399999,"10297159070.89130",2811376,"227838.755","5246060241.38648","0"] for the last candle. This checks out. (the values I'm particularly keeping an eye out are the: open: 22757.80, high: 23368.60, low: 22742.40 and close: 23234.10) However, for the same candle, node-binance-api returns: '1675728000000': { time: 1675728000000, closeTime: 1675814399999, open: '22759.40', high: '23998.90', low: '20941.50', close: '23253.90', volume: '189002.105', quoteVolume: '4344856857.73900', takerBuyBaseVolume: '99064.412', takerBuyQuoteVolume: '2281842110.48430', trades: 70487 } The particular candle we're comparing is for February 7th, 2023.

I'm assuming the error lies within the way node-binance-api is processing the websocket responses, but before I dig deeper into this, I figured I should ask someone more familiar with it.

GTedZ commented 1 year ago

I read somewhere in the Binance documentation that there are 2 types of candlesticks (kline and UIKline) where UIKline is adjusted for graphs, it could be that the normal HTTP request is requesting the normal kline candlesticks, whilst the websocket is automatically adjusted to give you UIKline from binance (since the UIKlines are only available via RESTful requests)

So it could be just that binance gives you the UIKlines by default via websocket

Anyways, this is to be available in my library binance-lib (once v3.0.0 is out in a couple days after some last tests) So you could check it out, plus it has FULL intellisense documentation for all Spot, Futures, Margin documentation including websockets and userData websockets. So check it out and tell me what you think!

Eluvade commented 2 months ago

I've overlooked something very obvious in my configuration.

test: 'true' fetches the data from Binance's testnet, which are completely independent markets that only loosely follow the price. I had incorrectly assumed that setting the test mode to "true" would merely emulate one's orders and would be using the same markets we're all used to trading with from either Binance or Tradingview.