Marfusios / bitmex-client-websocket

🛠️ C# client for Bitmex websocket API
Apache License 2.0
63 stars 44 forks source link

failure after some hours of running #19

Open Jiraiyah opened 5 years ago

Jiraiyah commented 5 years ago

@Marfusios Hi Please take a look at this issue, let a program that is reading your position size, wallet info and market price run for more than few hours (most likely between 12 to 15 hours), during these times, randomly close a position by API and open a new one or send some orders to change the size, you will see that after some hours, the websocket stops fetching the correct values. How did i find about this? I'm developing a bot and found that after around 12 hours, my bot is sending long signals for at least 3 times, knowing my own code, i would new that if there was any short positions, it would have been closed by the very first long signal. But,... the info section of the bot, that is using websocket, was showing that i had a short position with even wrong number !

investigating it farther, it looks like even the bitmex's own python version of websocket is having this type of issue and looks like only nodejs version is the one without ANY issue.

thinking about it, i think i came up with a dirty solution, every 30 minute or so, disconnect from websocket, reconnect and re register everything user asked for (authenticated and non authenticated) but do it under the hood so that no log or any sort of error rise up and being cached by the user side.

By doing this dirty trick, until bitmex move their sorry assess to solve many issues they have on their servers,... we should be able to refresh the websocket connections every 30 minutes. As much as i understand it, it looks like the connection keeps working for hours but then drops the validity of it from server side some how. although the ping works always, but the info from the authenticated section of websocket to be precise,... won't update any more.

And this happens without any disconnection/reconnection log info being captured. Right now, the solution i have? is to close the bot and reopen it and everything works for hours until it gets ugly again !

Marfusios commented 5 years ago

Hello,

my bots running 24/7 without issue, I'm subscribed mostly to authenticated API (orders) and public trades, order book. Could you integrate intensive logging and set Verbose level? Maybe there is some different problem.

Jiraiyah commented 5 years ago

Hello,

my bots running 24/7 without issue, I'm subscribed mostly to authenticated API (orders) and public trades, order book. Could you integrate intensive logging and set Verbose level? Maybe there is some different problem.

I think I know what is going on, i tend to download heavy files every now and then. and when that happens ping time increases on websocket, causing a dc. But then when it was reconnecting, i was not subscribing to authenticated streams again.

the main problem is, when you subscribe to authenticated streams in reconnection happened event , and at the same time out side of it, at the start you get some 401 errors. I know we can totally ignore them but it's not a nice thing. on the other hand, if you only subscribe in reconnection happened, it looks like it's working from start, but i noticed some issues, can't really describe it but it's there. so, the best way would be to subscribe manually at the start, and subscribe again in reconnection happened (like the winform example on repo) and look for 401 error message and filter it out and not show it in logs ! after doing it, right now i don't see any issue like before.

but here is another issue regarding websocket on bitmex, although, i'm not sure if it's bitmex's fault or the library is causing it. when a one minute candle closes, the trade bin for the last candles gets to the bot almost always after 15 seconds !