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.
Best Answer
-
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))0
Answers
-
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.
1
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛