tvdatafeed icon indicating copy to clipboard operation
tvdatafeed copied to clipboard

How to extend the max-number of candles from 5k to 20k (allowed by premium subscribtion) ?

Open galeese opened this issue 3 years ago • 8 comments

The provided below def get_hist loads maximum 5k candles. May be you know the technique of how to receive 20 k candles(which is the maximum allowed ) for the premium subscription?

May be you could rewrite the cycle loading portions of candles to address separate periods of time?

` while True: try: result = self.ws.recv() raw_data = raw_data + result + "\n" except Exception as e: logger.error(e) break

        if "series_completed" in result:
            break

The whole function: ` def get_hist( self, symbol: str, exchange: str = "NSE", interval: Interval = Interval.in_daily, n_bars: int = 10, fut_contract: int = None, ) -> pd.DataFrame: # self = self() symbol = self.__format_symbol( symbol=symbol, exchange=exchange, contract=fut_contract )

    interval = interval.value

    # logger.debug("chart_session generated {}".format(self.chart_session))
    self.__create_connection()
    # self.__send_message("set_auth_token", ["unauthorized_user_token"])

    self.__send_message("set_auth_token", [self.token])
    self.__send_message("chart_create_session", [self.chart_session, ""])
    self.__send_message("quote_create_session", [self.session])
    
    self.__send_message( "quote_set_fields", [ self.session, "ch", "chp", "current_session", "description", "local_description", "language", "exchange", "fractional", "is_tradable",
            "lp", "lp_time", "minmov", "minmove2", "original_name", "pricescale", "pro_name", "short_name", "type", "update_mode", "volume", "currency_code", "rchp", "rtc", ], )

    self.__send_message( "quote_add_symbols", [self.session, symbol, {"flags": ["force_permission"]}] )
    self.__send_message("quote_fast_symbols", [self.session, symbol])

    self.__send_message( "resolve_symbol", [ self.chart_session, "symbol_1", '={"symbol":"' + symbol + '","adjustment":"splits","session":"extended"}', ], )
    self.__send_message( "create_series", [self.chart_session, "s1", "s1", "symbol_1", interval, n_bars], )

    raw_data = ""

    logger.debug(f"getting data for {symbol}...")
    while True:
        try:
            result = self.ws.recv()
            raw_data = raw_data + result + "\n"
        except Exception as e:
            logger.error(e)
            break

        if "series_completed" in result:
            break

    return self.__create_df(raw_data, symbol)`

galeese avatar Jul 29 '21 06:07 galeese

I haven't tried with a premium account. Try and check if you succeed in downloading more than 5k bars

streamalpha avatar Jul 29 '21 16:07 streamalpha

I didn't manage to, yet trading view says it has 22k of candles available for the instrument i'm trying to download

galeese avatar Aug 05 '21 06:08 galeese

Did you manage to get 22k ?@galeese

djaym7 avatar Sep 10 '21 19:09 djaym7

no, i didn't to get 22k

пт, 10 сент. 2021 г. в 22:13, Jay Desai @.***>:

Did you manage to get 22k @.*** https://github.com/galeese

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/StreamAlpha/tvdatafeed/issues/19#issuecomment-917147814, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUU2O65BAF3BRJO2G5LDOTUBJKF7ANCNFSM5BFY7IHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- @.*** Roman Ishchenko

galeese avatar Sep 17 '21 18:09 galeese

I also have premium account but unable to download 1 min data of more than 5K candles.

cooltechie007 avatar Oct 23 '21 09:10 cooltechie007

yes, this because of the limitations occurring in python module. So be happy with 5k. By the way i never saw more than 5k candles on the charts. so don't get by what means one could retrieve 22k.. May be 22k is someones - dream?0)

сб, 23 окт. 2021 г. в 12:09, cooltechie007 @.***>:

I also have premium account but unable to download 1 min data of more than 5K candles.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/StreamAlpha/tvdatafeed/issues/19#issuecomment-950121505, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUU2OZGH372P5PYMNICO23UIJ3VHANCNFSM5BFY7IHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- @.*** Roman Ishchenko

galeese avatar Oct 23 '21 10:10 galeese

Hi,

For Pro users you just need to change __create_connection method in tvdatafeed/tvDatafeed/main.py :

def __create_connection(self):
        logging.debug("creating websocket connection")
        self.ws = create_connection(
            "wss://data.tradingview.com/socket.io/websocket", headers=self.headers
        )

to the following:

def __create_connection(self):
        logging.debug("creating websocket connection")
        self.ws = create_connection(
            "wss://prodata.tradingview.com/socket.io/websocket", headers=self.headers
        )

rezaho avatar Jan 15 '22 21:01 rezaho

Hi,

For Pro users you just need to change __create_connection method in tvdatafeed/tvDatafeed/main.py :

def __create_connection(self):
        logging.debug("creating websocket connection")
        self.ws = create_connection(
            "wss://data.tradingview.com/socket.io/websocket", headers=self.headers
        )

to the following:

def __create_connection(self):
        logging.debug("creating websocket connection")
        self.ws = create_connection(
            "wss://prodata.tradingview.com/socket.io/websocket", headers=self.headers
        )

Hi, i tried to set followed this but i still extend the max-number of candles 5k.

golfwhiper28 avatar Feb 07 '22 04:02 golfwhiper28

Thank you for the wonderful code. I am a premium user but unable to get 20k bars and these bars i want of 1 second, but this functionality also not there in the code. Please help.Thanks

hary4ever avatar Oct 13 '22 19:10 hary4ever

prodata

Problem solved with this code. Hopefully can integrate into future update

EasonLyon avatar Nov 24 '22 15:11 EasonLyon