-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Websocket send() command #402
Comments
Hi, it works a little differently with my SDKs. Individual WebSocket connections don't live forever, so the SDK treats them as replaceable. The WS Client will automatically send heartbeats on any active connections and if a dead connection is detected, it will automatically tear down and replace the connection with a healthy one, before resubscribing to all topics you were already subscribed to. This requires some state/knowledge (within the WS client) of which topics you've subscribed to, so it knows which ones to resubscribe to on reconnect, which is why all topic requests should be routed via the subscribeV5 method. There's also a unsubscribeV5 method: This is also why the individual websocket connections used by the WS client are not exposed directly (although you can access them if you really want to). For consuming events, you should use the event emitters on the WS client itself - which is an extra layer over it: If a reconnect happens, you don't need to resubscribe, you don't need to reconnect new event listeners - it's all automatic under the hood. In case you did want to check the REST API for anything you may have missed after the reconnect, there is a "reconnected" event indicating that it happened and successfully spawned a new connection to replace a dead one: If you're curious about how it works in practice, I highly recommend messing with your network connection while testing locally. Turn your wifi off for a while, or mess around with a VPN. No matter how long the interruption lasts, it should keep retrying until eventually respawning and resubscribing. |
Thanks for the fast and detailled response. I think i had to be more concise, the issue i have is not related to connection, but rather how to send (any) message to the server side from my client, using your websocket implementation. So with default nodejs ws, i would do ws.send(JSON.stringify({ op: "`something", args: [`something`] })); Whereas with yours, maybe this method? ws.trySend(ws.options.key, JSON.stringify({ op: "`something", args: [`something`] })) |
Yes, you will want the tryWsSend(key, messageAsString) method: By the way, if this is regarding the WebSocket API that Bybit has, I'm currently working on upgrades in the WebSocket client to support it properly, including a REST-like way of using the WS API wrapped in promises. No exact time-line as there's a fair few "plumbing" changes I will need to thoroughly stress test, but I'm hoping to have it ready by the end of this month at the latest... My gate.io SDK is actually the first one to see an implementation of a WS API and I'm likely to bring the same design over to the bybit SDK (as well as my other SDKs for exchanges that have a WS API). So if you'd like to see how that can work in practice, take a look at the gate SDK. Some docs here: Also an example here where you can see a minimal implementation in action: It's a great time for feedback/concerns, if you'd like to influence how the final implementation will look/work, so if this is something you will use please do take a look and ideally try it out. |
This is the thread to follow, if you want to stay updated on when it's ready: #344 |
Thank you alot for all the info and quick responses! Will keep an eye on #344 and eventually use gate.io if that fits my needs |
Emphasis on feedback! Any thoughts & concerns on the design implemented with gate so far are appreciated, since right now the one coming to Bybit will work in a similar way. It's the best time to influence it when it's not finished yet! |
Hi, i just implemented a websocket connection, which sends messages over the socket like
but refactored it to use your library, since yours handles auth, reconnects etc, which is great.
However, i cannot find a
send()
method in yourWebsocketClient
implementation, does it have a different name or am i missing something?Thanks in advance!
The text was updated successfully, but these errors were encountered: