Hi, I am new to Alpaca and have a problem while trying to close StreamConn properly.
I created a thread to wrap the StreamConn. I do the following while try to close the conn.
“”"
def stop(self, renew=False):
asyncio.get_event_loop().run_until_complete(
self.__conn.close(renew=renew)
)
“”"
The error message is:
Blockquote
2021-01-27 13:05:01,654 streamclient [ERROR] Error stopping websocket client: This event loop is already running.
Exception in thread Thread-1:
Traceback (most recent call last):
File “/usr/lib/python3.8/threading.py”, line 932, in _bootstrap_inner
self.run()
File /pyalgotrade/user_strategies/alpaca_trade/stream_client.py", line 151, in run
self.__client.run()
File “/pyalgotrade/user_strategies/alpaca_trade/stream_client.py”, line 111, in run
self.__conn.run(
File “/pyalgotrade/env/lib/python3.8/site-packages/alpaca_trade_api/stream2.py”, line 335, in run
loop.run_until_complete(self.consume())
File “/usr/lib/python3.8/asyncio/base_events.py”, line 608, in run_until_complete
return future.result()
asyncio.exceptions.CancelledError
Thank you for the help