API lseg timeout

augusto_krappa
augusto_krappa Newcomer
edited May 26 in Refinitiv Data Platform

Can you help me to adjust the code to not get timed out please? i would like to collect data for 1000 companies. My code currently is like that:


if not use_yfinance:    print("Getting Market Cap, Beta, etc.")    ticker_list = list(tickerStrings)  # Your ticker list    max_items = 50    results = []
    ld_connect()
    for i in range(0, len(ticker_list), max_items):        try:            chunk = ticker_list[i:i + max_items]            df_chunk = ld.get_data(                        universe= chunk,                        fields = [                            'TR.CLOSEPRICE',                            'TR.TotalReturn1Wk',                            'TR.TotalReturn1Mo',                            'TR.TotalReturn3Mo',                            'TR.TotalReturn6Mo',                            'TR.TotalReturn1YrCrossAsset',                            'TR.TotalReturn3YrCrossAsset',                            'TR.TotalReturn5YrCrossAsset',                            'TR.CompanyMarketCapitalizationLocalCurn',                            'TR.WACCBeta',                            'TR.NumberofSharesOutstandingActual(Period=FY0)',                            'TR.F.ComShrOutsTot(Period=FY0)',                            'TR.AvgDailyVolume30D',                            'TR.AvgDailyValTraded30D',                        ])            results.append(df_chunk)        except Exception as e:            try:                print(f"Error processing chunk {i//max_items + 1}: {e}")                print("Trying to process again in 10s")                time.sleep(20)                df_chunk = ld.get_data(                            universe= chunk,                            fields = [                                'TR.CLOSEPRICE',                                'TR.TotalReturn1Wk',                                'TR.TotalReturn1Mo',                                'TR.TotalReturn3Mo',                                'TR.TotalReturn6Mo',                                'TR.TotalReturn1YrCrossAsset',                                'TR.TotalReturn3YrCrossAsset',                                'TR.TotalReturn5YrCrossAsset',                                'TR.CompanyMarketCapitalizationLocalCurn',                                'TR.WACCBeta',                                'TR.NumberofSharesOutstandingActual(Period=FY0)',                                'TR.F.ComShrOutsTot(Period=FY0)',                                'TR.AvgDailyVolume30D',                                'TR.AvgDailyValTraded30D',                            ])                results.append(df_chunk)            except Exception as e:                print(f"Error processing chunk {i//max_items + 1}: {e}")    if results:        df_BR = pd.concat(results, ignore_index=False)        print(display(df_BR))    else:        print("No data retrieved.")
    ld.close_session()

Tagged:

Answers

  • Hello @augusto_krappa

    You didn't show where you are connecting to, but looks like you are using the Desktop Session to get data from LSEG Workspace. In this case, you will need to adjust the chunk size and inter-call request time to stay within the data threshold limits for Workspace.

    Currently, your code does not add in the inter-request delay, until the threshold is breached (exception condition), after which no amount of delay will help it.