Time out error when downloading bonds from the govsrch

Options

Dear community, I am trying to download bonds information data from the govsrch using the following code:

# Define the start and end dates
start_date = '2025-01-01'
end_date = '2025-06-30'

# Generate a list of dates between the start and end dates
date_range = pd.date_range(start=start_date, end=end_date)

# Convert to a list of strings if needed
date_list_as_strings = [date.strftime('%Y-%m-%d') for date in date_range]
rd.get_config()["http.request-timeout"] = 400
rd.open_session() df_tot = [] for t in date_list_as_strings:

response = search.Definition(
view = search.Views.GOV_CORP_INSTRUMENTS,
top = 10000,

filter = "((DbType eq 'CORP') and RCSAssetCategory eq 'A:J' and ((IssueDate ge "+t+" and IssueDate le "+t+")))",
navigators = "IssueDate(calc:sum_FaceIssuedUSD,calc:sum_FaceOutstandingUSD,calc:sum_FaceIssuedTotal,type:histogram,buckets:100)",
select = "IssuerOrgid,RIC,EJVAssetID,DTSubjectName,BusinessEntity,PI,FaceIssuedUSD,""FaceOutstandingUSD,IssueDate,CouponRate,MaturityDate,ISIN,RCSDomicileLeaf,RCSCountryOfIncorporationLeaf,DBSTicker,RCSDomicileGenealogy""IsESGBond,KPITypeDescription,IsGreenBond,MaturityStandardYield,InstrumentTypeDescription,IssuePrice,FaceIssuedTotal,CouponFrequencyDescription,RCSCurrencyLeaf""RCSBondGradeLeaf,RCSCoveredBondGenealogy,IsCallable,IsPutable,RCSUseOfProceedsLeaf,RCSCurrencyLeaf"

).get_data()
df=response.data.df

if t == start_date:
df_tot = df
else: df_tot = df_tot.append(df)
print(t)
df_tot.shape[0]

but I am getting the error:

An error occurred while requesting URL('http://localhost:9000/api/rdp/discovery/search/v1/').ReadTimeout('timed out')

This error pops out not always at the same "t" when I relaunch the code.

Can anyone help me?

Thanks!

Answers

  • Hello @Giacomo_C

    I think you might be hitting the rate limits as described in the Reference document for the search API. Running a complex search filter for every day in a date range might be causing this. You can try to optimize the query and reduce the number of calls and also pace out each successive call.

    To get help with formulating a search query, please raise a content ticket at LSEG MyAccount.

  • Giacomo_C
    Giacomo_C Newcomer

    Thank you Gurpreet,

    I added a sleep time of 5' and it seems to be working now.

    Do you know how can I except the timeout error?

    Thanks again

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    You can use the try/except command to catch the exception. For example:

    try:
        response = search.Definition(
                view = search.Views.EQUITY_QUOTES,
                filter = "AssetType eq 'EQUITY' and RCSAssetClass eq 'ORD' and IsPrimaryIssueRIC eq true",
                select = "DocumentTitle, RIC, AssetState",
                top=10000
        ).get_data()
        
        response.data.df
    except Exception as ex:
        print("Exception: "+str(ex))