Web Socket Streams

I use this code:

const ws = new WebSocket(`wss://stream.binance.com:9443/ws`);

const stream = JSON.stringify({
  method: "SUBSCRIBE",
  params: ["btcusdt@aggTrade"],
  id: 1,
});

ws.on("open", () => {
  console.log(`Connection opened!`);

  ws.send(stream);
});

I have a couple of questions:

  1. I read in docs: Raw streams are accessed at /ws/. I can I do that?
  2. After I use ws.send(stream); how can I get the response?
  1. Raw streams just means you’ll receive updates that were not processed in between the sending to the retrieval of the data. when you do the subscribe, you are already requesting that.
  2. just has with “open”, there’s other method available, one of the is “onReceive”, but this depends on your used library. As additional comment, this is more on the programming side of question, so the best would be redirecting to the library or programming language’s community to get better help, as this forum is mainly for direct questions on the API usage itself. :slight_smile:
1 Like