Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_hist in TvDatafeedLive Error #39

Open
JustKovalchuk opened this issue Jan 27, 2024 · 10 comments
Open

get_hist in TvDatafeedLive Error #39

JustKovalchuk opened this issue Jan 27, 2024 · 10 comments

Comments

@JustKovalchuk
Copy link

JustKovalchuk commented Jan 27, 2024

Sometimes when i try to execute get_hist in TvDatafeedLive instance or seis I get an Error. Other time it works good (with no Error). What can cause this behaviour?

symbols: BTCUSD, ETHUSD
exchange: COINBASE

Error output:
ERROR:tvDatafeed.main:Connection to remote host was lost.
ERROR:tvDatafeed.main:no data, please check the exchange and symbol

@HermanRoberth42quack
Copy link

i get the same for indexes, Symbol "DE30EUR" exchange, "OANDA". I have tried a few different symbols and exchanges, and all give the same error. I am using the get_hist() in other functions that are called quiet frequently, and the last few days/week ive just been getting connection error, check symbol and exchange.

It might be the frequency hat you are calling get_hist(), i changed my frequency that i call the function, now its more or less 50 50 weather i get the connection error or not. So your problem is wide felt, not jsut your exchange/symbol

@advxx
Copy link

advxx commented Feb 2, 2024

Having the same issue. It appears to happen randomly.
Having a series of subsequent calls and it appear to happen at random stages every time.
Always get the "ERROR:tvDatafeed.main:Connection to remote host was lost." error.
As HermanRoberth42quack's suggested I changed the frequency in the get_hist() calls (time.sleep()) to increase the period between calls. No effect. Same issue.

I remember increasing the series of calls when I first started using this about a year ago.
I think the server accepted something as close to 0.2 sec and then you got the 'connection refused' because
of the too tight request.

@sunilcns
Copy link

sunilcns commented Feb 7, 2024

Even I am facing similar issue... Sometimes it works and sometimes it doesn't work and throws below error. I tried to induce sleep(2) seconds as well. Looks like TvDataFeed is not a reliable solution.
Please let me know if we have a permanent fix for this.

ERROR:tvDatafeed.main:Connection to remote host was lost.
ERROR:tvDatafeed.main:no data, please check the exchange and symbol

@evil617
Copy link

evil617 commented Feb 7, 2024

Hi, unfortuantely I am also facing this problem. Very annoying.
A while loop, to keep trying to connect is a temporary fix, but it takes forever sometimes.

@advxx
Copy link

advxx commented Feb 7, 2024

Hi, unfortuantely I am also facing this problem. Very annoying. A while loop, to keep trying to connect is a temporary fix, but it takes forever sometimes.

I sure is. Lets see if we have somebody that will help us fix this.

@HermanRoberth42quack
Copy link

Okay , well we should be able to figure this out?..

Okay and you guys have also tried the get_hist() seis?

for tvDatafeedLive I get the same error.
For tvDatafeed I also get the error .

I was thinking using the TradingView- ta that has live data but no historical data and just adding it to a data frame . Like get hist from this and update history by appending new data at real-time intervals . Though this is a bit slower and not the best solution.

You guys have any other ideas?

I was also thinking if one can change the websockets in this tvDatafeed , right now it runs on websocket-client. But if one could change it to use websockets v12( latest version) maybe that would be a better connection.

@Sinansi
Copy link

Sinansi commented Mar 4, 2024

I have the same problem and it is random and it is so annoying.

ERROR:tvDatafeed.main:Connection to remote host was lost.
ERROR:tvDatafeed.main:no data, please check the exchange and symbol

@Pofatoezil
Copy link

I encountered the same issue, but in my case, it doesn't occur randomly. I need to fetch commodity data from different exchanges, but the timeout error only occurs when I'm fetching ES, NQ (from CME), and BTC.

I've tried several times, and the timeout error has never occurred with other commodity data. However, it always happens with ES, NQ, and BTC. Has anyone had a successful case of fetching data for these commodities?

data={}
data['txf']={'symbol':'TXF','exchange':'TAIFEX','df':None}
data['nk']={'symbol':'NK225M','exchange':'OSE','df':None}
data['es']={'symbol':'ES','exchange':'CME','df':None}
data['nq']={'symbol':'NQ','exchange':'CME','df':None}
data['ym']={'symbol':'YM','exchange':'CBOT','df':None}
data['cn']={'symbol':'CN','exchange':'SGX','df':None}
data['fdx']={'symbol':'FDXM','exchange':'EUREX','df':None}
data['brn']={'symbol':'BRN','exchange':'ICEEUR','df':None}
data['fesg']={'symbol':'FSEG','exchange':'EUREX','df':None}
data['btc']={'symbol':'BTCUSDT','exchange':'BINANCE','df':None}


for key in data.keys():
    print(f'fetch {key}')
    data[key]['df']=tv.get_hist(symbol=data[key]['symbol'],
                                exchange=data[key]['exchange'],
                                interval=Interval.in_daily,
                                n_bars=2500,fut_contract=1,fut_badj=True)
    time.sleep(5)

@ramasitafalam
Copy link

You guys can write a wrapper around the get_hist function. That's it. It works easy. And then you do retries based on your requirement. Max 10 retries are enough in general.

def get_hist(stock, feed, max_candles):
    # 8 is my lucky number. May this script generate a fortune for us.
    for i in range(88):
        try:
            history = feed.get_hist(symbol, "NSE", interval=Interval.in_daily, n_bars=max_candles, extended_session=False,)
            if history is None:
                stock.warn(f"{symbol} : Connection Lost while fetching!!!, retrying {i+1}")
            else:
                history['date'] = history.index.date
                return history
        except Exception as e:
            stock.warn(f"{symbol} : Exception while Fetching -> {e}!!!, retrying {i+1}")

@Sinansi
Copy link

Sinansi commented Mar 22, 2024

I am using a while loop instead of for loop. While the exception is triggered keep submitting the same query, up to 10 attempts. Usually the query does not exceed 3 or 4 attempts. In case of 10 attempts, then most likely something wrong with the symbol/stock itself. For example, the symbol is incorrect or the stock has been delisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants