Web Socket User Data Stream

Hello,

I’m trying to write a client javascript code (for browser) for fetching data for Web Socket User Data Stream. Based on documentation is not clear

  1. how to pass Security Key for getting a listenKey.
  2. how to get events data for Balance and Position update, Order update.

Please, help me modify the code below for getting Balance, Position, Order update through wss.

function OpenSocketBinance() {

var xhr = new XMLHttpRequest();
var listenKey = null;

//apiPath : 'https://testnet.binancefuture.com'

xhr.open("POST", apiPath + '/fapi/v1/listenKey/timestamp=', false);
xhr.setRequestHeader("X-MBX-APIKEY", apiKey);
xhr.send(null);

if (xhr.status === 200) 
    listenKey = (JSON.parse(xhr.responseText))['listenKey'];

// 'wss://stream.binancefuture.com'
ws = new WebSocket(`${wssPath}/ws/${listenKey}`);

//ws.setHandler('executionReport', (params) => log(params));
//ws.setHandler('outboundAccountInfo', (params) => log(params));   

}

You can’t using javascript. Generate your listenKey from your server end and get the key in your javascript code

From your code

for the method const privateRequest

you calc the signature but never used it. How does it work?

const signature = crypto
.createHmac(‘sha256’, apiSecret)
.update(buildQueryString({ …data, timestamp }).substr(1))
.digest(‘hex’);

requestClient.js is used by other js programs…
Please understand nodeJS better and find a nodeJS dev forum if you have question about the code