td-ameritrade-python-api icon indicating copy to clipboard operation
td-ameritrade-python-api copied to clipboard

Streaming client experiencing websocket connection termination before getting results

Open DewinGoh opened this issue 4 years ago • 1 comments

Hi, I've been trying out this library (great work by the way!). Have been running into a wall with this particular issue where the streaming client seems to get terminated on TD Ameritrade's side. Wondering if anyone has encountered this or if there is anything I should have done along the API setup that I missed out.

Probably hitting into this line: https://github.com/areed1192/td-ameritrade-python-api/blob/master/td/stream.py#L741

Logs:

Connection established. Streaming will begin shortly.

================================================================================
CLOSING PROCESS INITIATED:
================================================================================
WebSocket Closed: True
Event Loop Closed: True
================================================================================

Traceback (most recent call last):
  File "td_connect.py", line 25, in <module>
    td_stream_session.stream()
  File "/usr/local/lib/python3.8/site-packages/td/stream.py", line 534, in stream
    self.loop.run_until_complete(self._connect())
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
    raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.

DewinGoh avatar Dec 23 '20 17:12 DewinGoh

I'm currently working on this issue as well. It seems to be a problem with using ipython in an IDE that is also running asyncio. Try adding this at the beginning to allow nested asyncio loops.

import nest_asyncio nest_asyncio.apply()

cjmully avatar Feb 11 '21 23:02 cjmully