Please, you can sample code to JavaScript (jQuery, WebSocket) + PHP?
https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md
- Open a stream to wss://stream.binance.com:9443/ws/bnbbtc@depth.
- Buffer the events you receive from the stream.
- Get a depth snapshot from https://www.binance.com/api/v1/depth?symbol=BNBBTC&limit=1000 .
- Drop any event where u is <= lastUpdateId in the snapshot.
- The first processed event should have U <= lastUpdateId+1 AND u >= lastUpdateId+1.
- While listening to the stream, each new event's U should be equal to the previous event's u+1.
- The data in each event is the absolute quantity for a price level.
- If the quantity is 0, remove the price level.
- Receiving an event that removes a price level that is not in your local order book can happen and is normal.
function financial(val, limit=2){
return Number.parseFloat(val).toFixed(limit);
}
$("#get-depth").on('click', function(){
let socket = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@depth");
socket.onopen = function(){};
socket.onclose = function(event){};
socket.onmessage = function(event){
obj = JSON.parse(event.data);
let bR = '';
let aR = '';
let b = obj.b;
let a = obj.a;
$.each(b, function(k, v){
let bSum = parseFloat(v[0]) * parseFloat(v[1]);
bR = bR + '<tr><td>'+v[0]+'</td><td>'+v[1]+'</td><td>'+financial(bSum)+'</td></tr>';
});
$.each(a, function(k, v){
let aSum = parseFloat(v[0]) * parseFloat(v[1]);
aR = aR + '<tr><td>'+v[0]+'</td><td>'+v[1]+'</td><td>'+financial(aSum)+'</td></tr>';
});
$("#depth-bids tbody").html(bR);
$("#depth-asks tbody").html(aR);
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="get-depth">Get Depth</button>
<table id="#depth-bids"><tbody></tbody></table>
<table id="#depth-asks"><tbody></tbody></table>