Is there a way to automatically restart binance ThreadedWebsocketManager
when the internet connection was lost?

- 87
- 11
-
@samuehertrich if you have solved the issue could you please provide some code for the same.I am also struggling with this as i have no background in async programming and it will probably take some time to figure it out. – pppp_prs Nov 20 '21 at 21:00
-
@pppp_prs Unfortunately I haven't tried it yet but as soon as I have the code I will post it here. – samuelhertrich Nov 28 '21 at 11:37
1 Answers
Surely, as python-binance sdk is listing it as one of its features:
Websocket handling with reconnection and multiplexed connections
Since they are an open-source project, maybe having a look at their source code be helpful.
P.S. As the question author asked for more info: I searched github repository of python-binance for the phrase reconnect and the first result pointed me to where you expect.
In their latest version(which now reads 0.7.10) they have defined a complete class for this purpose, namely class ReconnectingWebsocket
based on python asyncio module. But in the version that i am accustomed to(0.7.5) they were using class ReconnectingClientFactory
from the twisted package to accomplish this.
... And to see how they have used this class, Just search their repository recursively until arriving to the point that they start to use their stuff rather than defining more stuff!
In this case(Version 0.7.10) the next phrase to search for is ReconnectingWebsocket which brings up declaration of class KeepAliveWebsocket(ReconnectingWebsocket):
. One more search to see what are they doing with KeepAliveWebsocket
shows this line in the body of the method _get_account_socket
of class BinanceSocketManager
so every time you are calling get_account_socket
you are implicitly implementing the functionality of ReconnectingWebsocket
to enjoy auto reconnecting feature of python-binance.
-
Can't find something like that in the source code. Can somebody show me where it is? – samuelhertrich Aug 13 '21 at 16:15
-
-
Thank you for your answer, now I just need to figure out where to put this into my code... – samuelhertrich Aug 14 '21 at 12:43
-
@samuelhertrich, I've added my idea about how they are using the ReconnectingWebsocket class. – S.Khajeh Aug 14 '21 at 15:38