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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
21 1 0 0

Using get_data with loop in python for historical data

I would like to download several infos and balance sheet items from several companies.

I keep in an SQL table a list of RICs that I imported as a list of integers [4295859221, ...] named rics and in another SQL table the list of the fields I want to download from Eikon as a DataFrame [TR.F.CashSTInvst, TR.TotalAssets, ...] named finstatDF.

So far, I just try to loop on the company RIC. I have seen an example that I tried to replicate but I get an error message. This is my code df, err =ek.get_data(rics[5], fields = ['TR.CommonName', 'TR.F.CashSTInvst'] , parameters={'Scale': 3, 'SDate': 0, 'EDate': -2, 'FRQ': 'FY', 'Curn': 'EUR'}).

How could I do ? Thanks in advance for your help.

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythonricssql
icon clock
10 |1500

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

Upvotes
Accepted
21 1 0 0

I managed to get it done and working by playing with the nature of my inputs as follows :

connect = sq.connect('\DB\Finlist.db')        # connect to the DB FinancialDB
cursor = connect.cursor()
cursor.execute("SELECT field1 FROM TRlistEuroPr")          
outp = cursor.fetchall()
rics = list(chain(*outp))
cursor.execute("SELECT TRRIC FROM TRdataFinStat")          
outp = cursor.fetchall()
listTR = list(chain(*outp))

dataTR, err = ek.get_data(str(rics[0]), listTR, {'Scale': 3, 'SDate': -40, 'EDate': -20, 'FRQ': 'FY', 'Curn': 'EUR'})
dataTR.to_sql("TRdataEuroPr", connect, if_exists='replace')
sq_table = "TRdataEuroPr"

for i in range(len(rics)):
    dataTR, err = ek.get_data(str(rics[i]), listTR, {'Scale': 3, 'SDate': 0, 'EDate': -40, 'FRQ': 'FY', 'Curn': 'EUR'})
    if len(dataTR) < 2:
        print('error', i)
    else:
        dataTR.drop(dataTR[pd.isnull(dataTR["Tot Assets"])].index, inplace=True)            #drop all rows where Total assets is null
        dataTR.to_sql(sq_table, connect, if_exists='append')  
        print(i, len(dataTR))
icon clock
10 |1500

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

Upvote
18k 21 12 20

Hi @j.dessain

The identifier should be String.


Please also review this API limitation guideline at https://developers.refinitiv.com/eikon-apis/eikon-data-api/docs?content=49692&type=documentation_item

For example, there is a 5-requests-per-second limitation on the document.

So you should add some idle in your loop.

Or you can make an API call with multiple identifiers.


ahs.png (91.6 KiB)
ahs2.png (36.3 KiB)
icon clock
10 |1500

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

Click below to post an Idea Post Idea