coinbasepro-python
coinbasepro-python copied to clipboard
Connection is already closed. - data: None -- OrderBook Socket Closed! --
After running the orderbook.py script for a few hours, I always run into this problem: Connection is already closed. - data: None
-- OrderBook Socket Closed! --
The script still runs - it doesn't exit but The connection is auto closed and goes into and endless looped sleep state. Anyone else experiencing this and know what the problem is? Thanks.
I'm experiencing it. I presume it's a result of some interruption in the TCP connection, either at GDAX's end or somewhere in the network in between. However I haven't spent time to investigate with any depth.
I'm handling it, at least temporarily, by setting a boolean (self.connected) to True in on_open, and False in on_close. And then in my main thread checking that occasionally and when I see that it is false I throw away my websocket client and create a new one to trigger a new connection. The WebsocketClient has a somewhat similar boolean (self.stop). Oh, and now that I look at the code again it should be flipped by an error like this as long as you haven't overridden the default on_error function. So you could probably poll for the state of that variable instead.
hi jheiss, thanks for your response. I am new to python and I'm not sure how to get the status of a variable in another module. What I noticed is that after I get the error, my try statement is still putting the script to sleep. So presumably, I can place the code which checks the state of self.stop here. Question is how do i grab the self.stop state in order_book.py from websocket_client.py? Thanks!
My attempt below:
order_book = OrderBookConsole() order_book.start() try: while True:
> while self.stop:
> order_book.close()
> order_book = OrderBookConsole()
> order_book.start()
print("sleeping") time.sleep(10)
Here's roughly what I'm doing:
while True:
order_book = OrderBookConsole()
order_book.start()
while not order_book.stop:
print("sleeping")
time.sleep(10)
order_book.close()
+1
I'm glad I'm not the only one seeing this message. It crashes my script within a few hours every time. I have noticed that a few of those times GDAX had posted a temporary maintenance period, not sure how related that is. Is this something that I should be handling in my script?