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

subscribeV5 unsubscribeV5 promise not resolved #399

Closed
pool683 opened this issue Dec 21, 2024 · 3 comments
Closed

subscribeV5 unsubscribeV5 promise not resolved #399

pool683 opened this issue Dec 21, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@pool683
Copy link

pool683 commented Dec 21, 2024

the following code breaks something

import { WebsocketClient } from 'bybit-api';

const wsClient = new WebsocketClient({
  market: 'v5',
});

wsClient.on('update', (data) => {
  wsClient.unsubscribeV5('tickers.' + data.data.symbol, 'linear');
  console.log("unsubscribeV5");
});

wsClient.on('error', (err) => {
  console.error(err);
});
   
console.log("before subscribeV5");
await wsClient.subscribeV5('tickers.' + 'BTCUSDT', 'linear');
console.log("never reach here!!!"); // <--- HERE

output

before subscribeV5
[
  'Starting public only websocket client.',
  { category: 'bybit-ws', wsKey: 'v5LinearPublic' }
]
[
  'Websocket connected',
  {
    category: 'bybit-ws',
    wsKey: 'v5LinearPublic',
    testnet: false,
    market: 'v5'
  }
]
[
  'Subscribing to topics',
  {
    category: 'bybit-ws',
    wsKey: 'v5LinearPublic',
    topics: [ 'tickers.BTCUSDT' ]
  }
]
unsubscribeV5
unsubscribeV5
unsubscribeV5
unsubscribeV5
unsubscribeV5
unsubscribeV5
@pool683 pool683 changed the title subscribeV5 unsubscribeV5 subscribeV5 unsubscribeV5 promise not resolved Dec 21, 2024
@tiagosiebler
Copy link
Owner

Apologies for the late response. I'm currently working through an upgraded WebSocket Client, as part of the addition of the WS API (#344). Once the upgrades are complete, I'll make sure this workflow works as expected with that release. You can follow (and comment on) the incoming changes in #398. I'll try to keep breaking changes minimal, so take anything currently in the PR with a grain of salt as that may still be subject to change.

@tiagosiebler tiagosiebler added the bug Something isn't working label Jan 14, 2025
tiagosiebler pushed a commit that referenced this issue Jan 20, 2025
@tiagosiebler
Copy link
Owner

Help test the latest generation of the Bybit SDK, currently in public beta, before the major release! There should also be a significant improvement to this behaviour (details in the PR, with some limitations).

More info here in the open PR:
#398 (comment)

@tiagosiebler
Copy link
Owner

During further testing, I'm seeing more circumstances where this has intended errors (unhandled promise rejection) if you weren't expecting to use this. So I've decided to disable this feature by default. The majority won't be using this as far as I can tell, so unexpected promise rejections will be avoided by just keeping it disabled by default. It will still work, but you need to actively enable it using the promiseSubscribeRequests setting in the websocket client. This is live as of v4.0.0-beta.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants