There are various functions available in Binance's Web Socket Streams including Aggregate Streams, Trade Streams, and Kline/Candlestick Streams. You can find more information about these functions here.
I am trying to retrieve the current price and last 24-hour percentage change of my selected coins in real time. However, I'm having trouble figuring out how to access this information. Ideally, the prices should be updated in real time, while the 24-hour percentage change can be refreshed every minute.
Currently, I am using CoinCap as a reference, which provides an easy way to:
- Retrieve the 24-hour percentage change by calling the endpoint
https://api.coincap.io/v2/assets?ids=bitcoin,ethereum
- Obtain real-time prices by calling the endpoint
wss://ws.coincap.io/prices?assets=bitcoin,ethereum
The issue with CoinCap is that it does not allow me to filter prices based on the exchange I prefer, which is Binance. As a result, I receive prices unrelated to Binance.
var socket = new WebSocket('wss://ws.coincap.io/prices?assets=bitcoin,ethereum');
socket.addEventListener('message', function (event)
{
// parse & show the data
});
For example, the Kline/Candlestick Streams description states:
The Kline/Candlestick Stream provides updates to the current klines/candlestick every second
It also presents the following data format:
{
"e": "kline", // Event type
"E": 123456789, // Event time
"s": "BNBBTC", // Symbol
"k": {
"t": 123400000, // Kline start time
"T": 123460000, // Kline close time
"s": "BNBBTC", // Symbol
"i": "1m", // Interval
"f": 100, // First trade ID
"L": 200, // Last trade ID
"o": "0.0010", // Open price
"c": "0.0020", // Close price
"h": "0.0025", // High price
"l": "0.0015", // Low price
"v": "1000", // Base asset volume
"n": 100, // Number of trades
"x": false, // Is this kline closed?
"q": "1.0000", // Quote asset volume
"V": "500", // Taker buy base asset volume
"Q": "0.500", // Taker buy quote asset volume
"B": "123456" // Ignore
}
}
Based on this data, what is the accurate current price matching the value displayed on the Binance Platform here?