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

Websocket - Binance Websocket.chart is not working 2024 #903

Open jhonyjss opened 5 months ago

jhonyjss commented 5 months ago

` const binance = new Binance().options({ APIKEY: apiKey, APISECRET: apiSecret, useServerTime: true });

binance.websockets.chart( "BTCUSDT", "1m", (symbol, interval, chart) => { console.info(chart); } );`

result: {}

Can you please check what's wrong ?

vitaly-t commented 4 months ago

Same here, just tried to use it, but the callback is streaming back the symbol string, not the data.

@jhonyjss Were you able to get to the bottom of it or find an alternative?

jhonyjss commented 4 months ago

Hi @vitaly-t , I didn't find any alternative yet. let's watch together.

vitaly-t commented 4 months ago

@jhonyjss Thank you for coming back to me on this!

After poking around with the API, I found that futuresCandlesticks works and gives me exactly what I wanted - socket subscription for candle updates, which is essentially the same stuff you would expect for the charting data.

            ['1m', '3m', '5m'].forEach(i => {
                const endpoint = binance.futuresCandlesticks('BTCUSDT', i, c => {
                    if (c.k.x) {
                        // candle has been closed, time to update:
                        this.updateCandles(i, {
                            open: c.k.o,
                            close: c.k.c,
                            high: c.k.h,
                            low: c.k.l,
                            openTime: c.k.t,
                            closeTime: c.k.T,
                            volume: c.k.v,
                            tradesCount: c.k.n
                        });
                    }
                });
                this.socketEndpoints.push(endpoint); // save the endpoint, to close later
            });

P.S. I work with Binance Futures only, I'm not interested in Spot stuff 😸