Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
5 0 0 4

Timeout Error retrieving data

Hi everyone,

I'm reaching out for some assistance regarding an eikon API query I've been working on.

I want to retrieve some data on the institutional ownership of 300 companies from 2002 until 2023 and I've encountered a timeout error (Error code 408 | Request timeout occurred) while executing the following code:

import eikon as ek
import pandas as pd
ek.set_timeout(100)

instruments = ['EQNR.OL' ,'DNB.OL' ,'NHY.OL' ,'TEL.OL' ,'YAR.OL' ,'AKRBP.OL' ,'MOWI.OL' ,'ORK.OL' ,'STB.OL' ,'TOM.OL' ,'GJFG.OL' ,'KOG.OL' ,'ADEA.OL' ,'SALM.OL' ,'NOD.OL' ,'SCHB.OL' ,'SCHA.OL' ,'SRBNK.OL' ,'MING.OL' ,'BRGB.OL' ,'VAR.OL' ,'AKER.OL' ,'TGS.OL' ,'AUTO.OL' ,'PROT.OL' ,'EPR.OL' ,'ELK.OL' ,'LSG.OL' ,'ATEA.OL' ,'WAWI.OL' ,'AKSOA.OL' ,'HAUTO.OL' ,'ENTRA.OL' ,'SCATC.OL' ,'NEL.OL' ,'VEI.OL' ,'DNO.OL' ,'CRAYN.OL' ,'AUSS.OL' ,'MPCC.OL' ,'WWI.OL' ,'SPOLS.OL' ,'GSFG.OL' ,'ACCA.OL' ,'HEX.OL' ,'BONHR.OL' ,'EQNR.N' ,'AKH.OL' ,'BNOR.OL' ,'NONG.OL' ,'PGS.OL' ,'NAS.OL' ,'RECSI.OL' ,'NYKD.OL' ,'NSKOG.OL' ,'GCC.OL' ,'BELCO.OL' ,'AFK.OL' ,'ASA.OL' ,'BEWI.OL' ,'ELMRA.OL' ,'ELO.OL' ,'HPUR.OL' ,'LINK.OL' ,'PEXIP.OL' ,'SBOS.OL' ,'VOLUE.OL' ,'XXL.OL' ,'DOFG.OL' ,'KIT.OL' ,'RANA.OL' ,'KID.OL' ,'HAVI.OL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,'OSUN.OL' ,'OTOVO.OL' ,'OTS.OL' ,'PCIB.OL' ,'PHLY.OL' ,'PNOR.OL' ,'PPGP_p.OL' ,'PROXI.OL' ,'PRSO.OL' ,'RCR.OL' ,'REACH.OL' ,'ROMER.OL' ,'ROMSB.OL' ,'SB68.OL' ,'SCANA.OL' ,'SKAND.OL' ,'SKUE.OL' ,'SMOP.OL' ,'SNOR.OL' ,'SOFTX.OL' ,'SOGNS.OL' ,'SPIR.OL' ,'STST.OL' ,'STSU.OL' ,'SUNSB.OL' ,'TECH.OL' ,'TECO.OL' ,'TEKNA.OL' ,'TYSB.OL' ,'VGM.OL' ,'VISTN.OL' ,'VVL.OL' ,'WEST.OL' ,'WSTEP.OL' ,'XPLRA.OL' ,'ZWIPEZ.OL']

def split_instruments(instruments, chunk_size=5):
    """Yield successive chunk_size chunks from instruments."""
    for i in range(0, len(instruments), chunk_size):
        yield instruments[i:i + chunk_size]

instrument_chunks = list(split_instruments(instruments))

dfs = []

for chunk in instrument_chunks:
    # Fetch data for the current chunk of instruments
    df_chunk = ek.get_data(
        instruments=chunk,
        fields=[
            'TR.PctOfSharesOutHeld.date',
            'TR.PctOfSharesOutHeld',
            'TR.InvestorFullName'
        ],
        parameters={'SDate': '2002-01-01', 'EDate': '2024-01-01', 'Frq': 'FY'}
    )[0] 

       filtered_df = df_chunk[df_chunk['Investor Full Name'].str.contains("Vanguard|BlackRock|State Street", case=False, na=False)].copy()
      
    filtered_df['Date'] = pd.to_datetime(filtered_df['Date'])
    filtered_df['Date'] = filtered_df['Date'].dt.year
    filtered_df.rename(columns={'Date': 'Year'}, inplace=True)
    
    dfs.append(filtered_df)

final_df = pd.concat(dfs, ignore_index=True)

print(final_df)

Until about a month ago, this code was working fine for fetching data from up to 50 companies. But now, even with the same companies as before, it's giving me a timeout error (Error code 408 | Request timeout occurred) so, I'm seeking guidance on how to resolve this timeout issue. Any gentle suggestions or optimizations would be greatly appreciated.

Thank you all in advance for your help!

eikon-data-apipythonworkspace#technologyerror-408
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
5.6k 18 2 7

Hi @jon.alonso ,


I can see you have already increased the timeout and are using chunks. Another approach I might suggest is to introduce a while loop to handle Timeout extensions as suggested in this thread -Recommended code pattern for handling Eikon get_data timeout - Forum | Refinitiv Developer Community - Forum | Refinitiv Developer Community. In the meantime I will check with the product team to check if there are issues on the API side.


Best regards,

Haykaz

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
5 0 0 4

Hi @aramyan.h I solved the issue forcing the code to retry several times, I provide the solution in case anyone can find it valuable:


import time
import eikon as ek
import pandas as pd
ek.set_timeout(200)

instruments = ['EQNR.OL' ,'DNB.OL' , ...]
dataframes = {}

# Loop through each instrument and fetch data
for instrument in instruments:
    success = False
    retries = 100
    for attempt in range(retries):
        try:
            df, err = ek.get_data(
                [instrument],
                ['TR.CompanyName','TR.PctOfSharesOutHeld.date', 'TR.PctOfSharesOutHeld', 'TR.InvestorFullName'],
                parameters={'SDate': '2002-01-01', 'EDate': '2024-01-02', 'Frq': 'FY'}
            )
            if err is None:
                dataframes[instrument] = df
                success = True
                print(f"Data successfully retrieved for {instrument}")
                break  # Exit the retry loop on success
        except ek.EikonError as e:
            print(f"Attempt {attempt + 1} failed for {instrument}: {e}")
            time.sleep(5)  # Wait 5 seconds before retrying
        
        if not success and attempt == retries - 1:
            print(f"Failed to retrieve data for {instrument} after {retries} attempts.")
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I am sure it will, thank you!

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.