rongardF / tvdatafeed

A simple TradingView historical Data Downloader
MIT License
242 stars 129 forks source link

Forex Data not runs? #35

Open optimvsjag opened 9 months ago

optimvsjag commented 9 months ago

Hi team,

I find this excellent lib today and I'm testing it with my PRO TV account and runs for stocks, crypto or futures but not for forex pairs.

I didn't found any example for forex pair in the guide and I'm testing with majors pairs like EURUSD and not run in any exchange (FXCM, ICE, OANDA, etc)

Print this error in the terminal:

ERROR:tvDatafeed.main:Connection timed out ERROR:tvDatafeed.main:no data, please check the exchange and symbol

I'm using this code to get EURUSD FX data: eurusd_data = tv.get_hist(symbol='EURUSD',exchange='FXCM',interval=Interval.in_daily,n_bars=10000)

Can be an issue or forex needs other code?

Thanks a lot.

liebig commented 9 months ago

Hi, I can confirm that FXCM and e.g. FOREX.com do not work as an exchange, or that they close with the error message you mentioned. But OANDA as an exchange works, maybe that's enough for you?

optimvsjag commented 9 months ago

Hi, I can confirm that FXCM and e.g. FOREX.com do not work as an exchange, or that they close with the error message you mentioned. But OANDA as an exchange works, maybe that's enough for you?

Thanks @liebig I tested again and runs OANDA for EURUSD but not for other pairs. I find this URL https://tvdb.brianthe.dev/ to search what exchange can download for any ticker and take "FX_IDC" for all forex pairs and runs ok.

But I've another problem, I use a for loop to download many tickers and when one ticker can't download returns "ERROR:tvDatafeed.main:no data, please check the exchange and symbol" and stop the loop.

Should print the error message but continue with other pairs. At the moment I am deleting the problematic tickers but it is a heavy work for any market.

Any idea to protect this problem?

liebig commented 9 months ago

A loop should actually work, as no error is thrown here, only an error message is logged. This is roughly what my loop looks like:

    for symbol in symbols:
        logger.info(f"Download {symbol} from {exchange} for {interval} interval and {bars} bars")
        hist_df = tvl.get_hist(symbol,
                               exchange,
                               interval=Interval(interval),
                               n_bars=bars,
                               fut_contract=None,
                               extended_session=False)

        if hist_df is None or hist_df.empty:
            logger.error(
                f"Could not download data for {symbol} from {exchange} for {interval} interval and {bars} bars")
            continue

        hist_df.to_csv(basename, index=True)

Currently I use my fork of this library to get more historical data via Pro membership and to save the login token as token.txt and not always have to log in again.

EDIT Okay, this only works because of the fix from https://github.com/traderjoe1968/tvdatafeed/commit/21e12f38bf9565e924b2428278a03b760e51dfc9

optimvsjag commented 9 months ago

A loop should actually work, as no error is thrown here, only an error message is logged. This is roughly what my loop looks like:

    for symbol in symbols:
        logger.info(f"Download {symbol} from {exchange} for {interval} interval and {bars} bars")
        hist_df = tvl.get_hist(symbol,
                               exchange,
                               interval=Interval(interval),
                               n_bars=bars,
                               fut_contract=None,
                               extended_session=False)

        if hist_df is None or hist_df.empty:
            logger.error(
                f"Could not download data for {symbol} from {exchange} for {interval} interval and {bars} bars")
            continue

        hist_df.to_csv(basename, index=True)

Currently I use my fork of this library to get more historical data via Pro membership and to save the login token as token.txt and not always have to log in again.

EDIT Okay, this only works because of the fix from traderjoe1968@21e12f3

Thanks for your answer. My loop error is when can't download one ticker data, the lib stops the loop and not continue with next tickers (this tickers exist in TV) but returns error. I deleted manually this conflictive tickers and now runs perfect for all TV pairs, about 2000. I made a reduced list with majors, minors and exotics pairs with 115 results and it is enought in my app for forex marquet. Can be a great upgrade in this lib to solve this problem in a future.