-
Notifications
You must be signed in to change notification settings - Fork 525
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
Connection to remote host was lost #258
Comments
Hi,
|
@sunshineinwater and @capsian, there's a solution available to address this issue and re-establish the WebSocket connection. Let me demonstrate one approach for you. while True:
my_client = None
try:
my_client = SpotWebsocketStreamClient(
on_message=message_handler,
on_error=error_handler,
on_close=close_handler
)
[my_client.agg_trade(symbol=symbol) for symbol in symbols]
while True:
time.sleep(10) # check every ten seconds if the websocket is alive
if not my_client.socket_manager.is_alive():
raise Exception("WebSocket connection is not alive")
# You might want to contemplate the utilization of an additional condition, such as an 'if' statement or a condition variable, if your intention is to terminate the connection once a different condition has been met.
except Exception as e:
my_client.stop()
else:
# other instruction
#.
#.
#.
my_client.stop()
break |
thanks a lot , but I don't understand the usage at the end of code:
|
These 'other instructions' are just Python code that needs to be executed before closing the WebSocket. |
I've just submitted a pull request that solves this issue. The solution I come up with is that after an exception occur, it calls the on_error callback before exiting the main loop. So one can handle the exceptions in the on_error callback. |
Use Unicorn. I've moved to Unicorn and that's fixed a lot of my issues with this connector. Also reduce the number of ingestible requests, for instance from 100ms to 1000ms. Better to have 1s data with good integrity than 100ms data that crashes every minute (in my case). |
Issue subject
Expected behaviour
run forever
Python Code
Environment
Provide any relevant information about your setup, such as:
The text was updated successfully, but these errors were encountered: