gateio / gatews

Gate Websocket V4 SDK
89 stars 35 forks source link

Websocket connection stability #40

Open mengoudis opened 1 year ago

mengoudis commented 1 year ago

Hello everyone.

I have noticed many frequent random disconnects from the Gate.io websocket server. Everything is stable when connecting to the websocket servers of 3 other major exchanges (and the code can run for days) but the connection to Gate.io is unstable. It disconnects with no apparent reason, it does not seem to close the connection, it seems more like just sitting idle and not sending any updates. Ping / pong protocol is respected with the connection (even though their documentation is vague about it).

Do you have any specific advice about how to handle Gate.io websocket connections? Maybe something that is not apparent in the docs or anything else?

Thank you in advance.

revilwang commented 1 year ago

Could you provide the server endpoint you’re connecting to? And some disconnection logs will also be great help!

mengoudis commented 1 year ago

Hi, thanks for the quick reply.

I connect to wss://api.gateio.ws/ws/v4/ and I send a subscription message like {"time": '.time().', "channel": "spot.order_book", "event": "subscribe", "payload": ["tt_usdt", "100", "100ms"]}.

I am using the "ratchet/pawl": "^0.3.5" library to run my php code as a websocket client.

I do not have any network logs, at least my code does not keep any, but I am sure something is not right because the "onclose" event handler that triggers when a connection is closed by the other exchanges, for example when I do not send a ping/pong, does not trigger at all for Gate.io. I am not even sure if the connection is dropped, I just do not get any data for long periods of time (and I assume the connection was closed or something).

khunspoonzi commented 4 months ago

Did you ever get this resolved? @mengoudis

I've observed very similar behavior on my side as well. Seemingly the connection is not broken but then for a period it seems like I completely stop receiving deltas altogether. And then after several minutes, they resume streaming in.

@revilwang Interested to get your input on this as well since you have some great example implementations on your profile. Has this ever been a known issue for you at any point?

mengoudis commented 4 months ago

nope... did not end up fixing it. And because we do not currently use gate.io very much, we did not focus on this.

but it will need to get fixed at some point.

khunspoonzi commented 4 months ago

Noted thanks. I'll follow up if I do end up figuring it out. Would still love to get input from @revilwang in case this issue has been raised elsewhere as well.

revilwang commented 4 months ago

We've been fixing server issues constantly. As this is the repo of client SDK, I would suggest sending any server related issues with detailed requests to the official support entry.