error: An existing connection was forcibly closed by the remote host

Hobby Q. shared this problem 4 years ago
Solved

I am using the test application found on Git.

It cannot seem to hold a connection for longer than about 5 minutes. I get a few bars, then every time I get this error when trying to stream bars.

[WinError 10054] An existing connection was forcibly closed by the remote host
The app seems to keep running (I am assuming its some thread that is running), but bars stop flowing.

Best Answer
photo

Update - Though you would already be aware by now, I am updating this thread for benefit of all, with the information that, automatic reconnect was enabled in Version 3.0.2 on Apr 21, 2021.

Version 3.0.2

  • Automatic streaming websocket reconnect enabled.
  • Automatic subscription of symbols & restart of live data after reconnect
  • Now Avoiding server calls for repeated / duplicate streaming symbols...
    The latest version is version 4.2.2. >> https://pypi.org/project/truedata-ws/
    Please make sure you have the latest version.
    pip install truedata-ws

Replies (7)

photo
1

Please go to https://wstest.truedata.in/ first to test everything.

Add your credentials and the very same symbols which you are pulling from the Git code.

Let me know what happens and then we will move ahead.

photo
1

This seems stable.

So maybe your sample code is not stable.

This is the code I use:

from truedata_ws.websocket.TD import TD
from copy import deepcopy
import pandas as pd
import time
import datetime

usname = 'my username'
psword = 'my password'
td_app = TD(usname, psword, broker_token=None, live_port=8084, historical_port=8094)
symbols = ['CRUDEOIL-I', 'NIFTY-I', 'RELIANCE', 'ITC']

req_ids = td_app.start_live_data(symbols)
live_data_objs = {}
time.sleep(1)
for req_id in req_ids:
live_data_objs[req_id] = deepcopy(td_app.live_data[req_id])
print(live_data_objs[req_id])
print(f'touchlinedata -> {td_app.touchline_data[req_id]}')

while True:
for req_id in req_ids:
if not td_app.live_data[req_id] == live_data_objs[req_id]:
print(td_app.live_data[req_id].__dict__)
live_data_objs[req_id] = deepcopy(td_app.live_data[req_id])

photo
1

One thing I noticed on https://wstest.truedata.in/ is that it shows heartbeats.

The sample code I use doesn't show any heartbeats.

Perhaps this is why the socket is closed. I have tried to google this error and it seems that many times this error occurs because the client and server cannot agree on whether the connection is alive or not.

photo
1
  1. The sandbox environment shows the raw feed directly from the server.
  2. The sample code you are using uses the python library hosted at > Check code & docs here
  3. The python library manages the heartbeats internally and does not show them to you.
  4. Your code does not seem to be formatted correctly.
  5. Make sure you meet all the prerequisites for the library > eg. Min python version is 3.7
  6. Please use this code below for the real-time portion of the stream & remove broker_token=None from your object / code above.

req_ids = td_app.start_live_data(symbols)
live_data_objs = {}

time.sleep(1)
for req_id in req_ids:
    live_data_objs[req_id] = deepcopy(td_app.live_data[req_id])
    print(td_app.touchline_data[req_id])
    print(f'touchlinedata -> {td_app.touchline_data[req_id]}')

while True:
    for req_id in req_ids:
        if not td_app.live_data[req_id] == live_data_objs[req_id]:
            print(td_app.live_data[req_id].__dict__)
            live_data_objs[req_id] = deepcopy(td_app.live_data[req_id])

photo
1

1. ok - but I am not sure how that deals with my problem

2. correct. this is what your documentation says. I went through your installation instructions. You can actually see this in the import statements

3. ok

4. of course, because I copied / pasted and this forum lost all my indentations

5. version I am using is 3.8.3 32 bit

6. the code you send is identical to my code. did I miss something?


By the way: I am not sure what happened on your side, but right now the feed has been up for the last 2 hours.

Maybe somehting got fixed on your side?!?! of course I am only getting CRUDEOIL-I prices right now because markets are closed. So I will wait for tomorrow's market session. Thanks!

photo
1

Finally !

We did nothing!

Lets check tomorrow to see if you get any issues.

photo
1

My sample code stopped with [WinError 10054] An existing connection was forcibly closed by the remote host

/1ec0c4c3d422cecc4de32b48a8aca67e


and your test website too:

/1d549cf4c1deda07f41914d3db8838a5

photo
1

Yes, the connection gets reset once in the morning.

We also upload any updates etc at this time.

We have pushed an update for the python library also.

Please upgrade the library also. version 1.0.0 now.

photo
1

oh, but your sample code does not handle the reconnect.

photo
1

Not yet, but reconnect, is under development and testing and will come with this library soon.

photo
1

Update - Though you would already be aware by now, I am updating this thread for benefit of all, with the information that, automatic reconnect was enabled in Version 3.0.2 on Apr 21, 2021.

Version 3.0.2

  • Automatic streaming websocket reconnect enabled.
  • Automatic subscription of symbols & restart of live data after reconnect
  • Now Avoiding server calls for repeated / duplicate streaming symbols...
    The latest version is version 4.2.2. >> https://pypi.org/project/truedata-ws/
    Please make sure you have the latest version.
    pip install truedata-ws

photo
Leave a Comment
 
Attach a file