tastytrade: AlertStreamer Hearbeat Exception
Hi, when I’m running my code using tastytrade 9.14 the AlertStreamer generates the following error from time to time while a session to Tastytrade is open:
Task exception was never retrieved
future: <Task finished name='Task-15' coro=<AlertStreamer._heartbeat() done, defined at C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\site-packages\tastytrade\streamer.py:336> exception=ConnectionClosedOK(Close(code=1000, reason='Bye'), Close(code=1000, reason='Bye'), True)>
Traceback (most recent call last):
File "C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\site-packages\tastytrade\streamer.py", line 343, in _heartbeat
await self._subscribe(SubscriptionType.HEARTBEAT, "")
File "C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\site-packages\tastytrade\streamer.py", line 369, in _subscribe
await self._websocket.send(json.dumps(message)) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\asyncio\connection.py", line 476, in send
async with self.send_context():
File "C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 210, in __aenter__
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Heiko\AppData\Local\Programs\Python\Python312\Lib\site-packages\websockets\asyncio\connection.py", line 957, in send_context
raise self.protocol.close_exc from original_exc
websockets.exceptions.ConnectionClosedOK: received 1000 (OK) Bye; then sent 1000 (OK) Bye
It seems like the keepalive WebSocket connection is closed from Tastytrade without an error but with reason ConnectionClosedOK.
However this case seems not to be handled. I’d expect that the AlertStreamer tries to reestablish the WebSocket Connection again in this case.
Is any additional information required?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (20 by maintainers)
Commits related to this issue
- try to fix #229 — committed to Mytak/tastytrade by Graeme22 2 years ago
Yup! That would be your problem. For some reason I had assumed you were already using the reconnect functionality! You can read about it here: https://tastyworks-api.readthedocs.io/en/latest/data-streamer.html#retry-callback
This code works for me even if I disable my internet for 30 seconds then turn it back on: