Wrong data from websocket

Hi! I am using official library for node js, Trying to get 24 hour rolling window price change statistics - when I got data from rest api using method get24hrTicker() (/fapi/v1/ticker/24hr) and data looks good. When I am trying to get updates from websocket for same data using allMarketTickersStreams () method (!ticker@arr - stream) I’ve got inconsistence data, for example -
rest api url ‘https://fapi.binance.com
Sending Websocket connection to: wss://stream.binance.com:9443/ws/!ticker@arr (also used wss://fstream.binancefuture.com/ws/!ticker@arr with same result)

{
symbol: ‘BTCUSDT’,
priceChange: ‘-882.60’, p: ‘-869.58000000’,
priceChangePercent: ‘-0.838’, P: ‘-0.825’,
weightedAvgPrice: ‘105387.23’, w: ‘105441.88002567’,
lastPrice: ‘104438.50’, c: ‘104480.43000000’,
lastQty: ‘0.034’, Q: ‘0.00097000’,
openPrice: ‘105321.10’, o: ‘105350.01000000’,
highPrice: ‘107076.50’, h: ‘107120.00000000’,
lowPrice: ‘104040.60’, l: ‘104106.09000000’,
volume: ‘136025.419’, v: ‘18544.76953000’,
quoteVolume: ‘14335341483.87’, q: ‘1955395363.88602590’,
openTime: 1737718320000, O: 1737718352160,
closeTime: 1737804745702, C: 1737804752160,
firstId: 5892986742, F: 4461111027,
lastId: 5896211200, L: 4464894897,
count: 3223670 n: 3783871
}
{
e: ‘24hrTicker’,
E: 1737804752161,
x: ‘105350.01000000’,
b: ‘104480.43000000’,
B: ‘0.46108000’,
a: ‘104480.44000000’,
A: ‘3.33153000’,
}

{
symbol: ‘ETHUSDT’, s: ‘ETHUSDT’,
priceChange: ‘-106.11’, p: ‘-107.18000000’,
priceChangePercent: ‘-3.120’, P: ‘-3.149’,
weightedAvgPrice: ‘3346.22’, w: ‘3346.06434738’,
lastPrice: ‘3295.18’, c: ‘3296.30000000’,
lastQty: ‘0.021’, Q: ‘0.54610000’,
openPrice: ‘3401.29’, o: ‘3403.48000000’,
highPrice: ‘3429.99’, h: ‘3428.00000000’,
lowPrice: ‘3266.53’, l: ‘3268.66000000’,
volume: ‘2221125.247’, v: ‘319672.18070000’,
quoteVolume: ‘7432371060.24’, q: ‘1069643686.68933400’,
openTime: 1737718320000, O: 1737718352159,
closeTime: 1737804746332, C: 1737804752159,
firstId: 5057272064, F: 2083063404,
lastId: 5061003878, L: 2084978139,
count: 3731434 n: 1914736
}

{
e: ‘24hrTicker’,
E: 1737804752160,
x: ‘3403.43000000’,
b: ‘3296.30000000’,
B: ‘26.64270000’,
a: ‘3296.31000000’,
A: ‘33.80730000’,
}
As I see First trade ID, Last trade Id very inconsistence for same period, so volume, trades count etc of course inconsistence too. Is any right way to update data from 24hr rest api using websocket?
P.S Even more - some fields from ws response don’t exists in documentation(All Market Tickers Streams | Binance Open Platform), like x, b, B, a, A

Spot and Futures are different markets.

They have similar, but different APIs, and trade different things. Node.js libraries are also different.

Spot Futures
REST API https://api.binance.com/api/v3/ticker/24hr https://fapi.binance.com/fapi/v1/ticker/24hr
WebSocket stream wss://stream.binance.com/ws/!ticker@arr wss://fstream.binancefuture.com/ws/!ticker@arr
Connector library @binance/connector @binance/futures-connector
Documentation Web Socket Streams | Binance Open Platform Connect | Binance Open Platform

it’s obvious that Spot and Futures are different markets, My example about futures, and I use GitHub - binance/binance-futures-connector-node: Simple NodeJS connector to Binance Futures API. If you are about using wss://stream.binance.com:9443 - it’s just to trying anything, because wss://fstream.binancefuture.com doesn’t work as described in official documentation. The main sense, that behavior of !ticker@arr doesn’t match with documentation, and n field contains some accumulated count of trades, but not for 24h window as expected according documentation, so it’s useless, And I can’t use websocket data to update data from rest api

Sure - just checked again - what I am doing wrong ? (even tried with VPN)


around 61200 it’s definitely not trades count of BTCUSDT for 24hr

Added one more screen to compare with rest api

Are you sure? “n” seems to go up and down for me, the difference between “O” and “C” is roughly 24 hours, and the timing of trades matches /fapi/v1/historicalTrades

1 Like

Finally we can close topic - the problem in web socket url in official library, it’s default value btw. ilammy thx for your answers, without your answer I’ve just switched to using rest api in 1 minute interval

Correct url for web socket is wss://fstream.binance.com
wss://fstream.binancefuture.com - provide wrong data