Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No messages received when trying to connect stream directly. #497

Open
devdynam0507 opened this issue Jan 2, 2025 · 1 comment
Open

Comments

@devdynam0507
Copy link

devdynam0507 commented Jan 2, 2025

Problems

const wsClient = new WebsocketClient();
const pairs = ["BTCUSDT", "ETHUSDT", ... ];
const session = wsClient.connectToWsUrl("wss://fstream.binance.com/stream");

wsClient.on("message", data => {
  const messageJson = JSON.stringify(data, null, 2);
  console.log("raw message received ", messageJson);
});

wsClient.on("open", data => {
  console.log("connection opened open:", data.wsKey, data.ws.target.url);
  const topics = pairs.data.map(symbol => `${symbol.toLowerCase()}@aggTrade`)
  const topicChunks = chunkArray(topics, 100);

  topicChunks.forEach((chunk, index) => {
    const subscribeMessage = {
      method: "SUBSCRIBE",
      params: chunk,
      id: index + 1,
    };

    // 구독 메시지 전송
    session.send(JSON.stringify(subscribeMessage));
  });
});

In this case printed console message to
'Bug? Unhandled ws message event type. Check if appendEventIfMissing needs to parse wsKey.',

The onMessage event I defined does not call with the warning log.

directly like this https://github.com/tiagosiebler/binance/blob/master/src/util/requestUtils.ts#L269
e field is not populated in wsMsg

https://github.com/tiagosiebler/binance/blob/master/src/websocket-client.ts#L403
The message event is not emitted at line 403 in websocket-client.ts.

So, as a temporary solution I

const session = wsClient.connectToWsUrl("wss://fstream.binance.com/stream", "bookTicker");

I solved it this way. Is this the correct action?

So I think, why not add a reserved key like 'directly' to wsKey?

@tiagosiebler
Copy link
Owner

It wasn't designed to be used like this, you may see other issues by using the WS client this way... is this to have multiple websocket topics on one connection?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants