Optimizing Eikon API Calls for Retrieving Fundamental Data
Hey everyone,
I'm working on a project on a codebook workspace where I need to pull a lot of fundamental data(322 fields) for various companies using their RICs via the Refinitiv Eikon API. The problem I'm facing is that the process is taking way too long, and I'm frequently running into gateway timeouts (Error code 2504).
- Long Processing Time: The entire process is very slow.
- Gateway Timeouts: Getting frequent gateway timeouts (Error code 2504), especially with larger batches.
EXPORT_FIELDS = [
"TR.F.TotRevPerShr(Curn=USD)",
"TR.F.SalesOfGoodsSrvcNet(Curn=USD)",
"TR.Revenue(Curn=USD)",
"TR.F.COGS(Curn=USD)",
"TR.F.COGSUNCLASSIF(Curn=USD)",
"TR.F.OpExpnTot(Curn=USD)",
"TR.F.SGATot(Curn=USD)",
"TR.F.EBITDANorm(Curn=USD)",
"TR.F.DeprDeplAmortTot(Curn=USD)",
"TR.F.RnD(Curn=USD)",
# 311 more fields...
]
ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')
def process_single_company(company):
max_attempts = 4
attempts = 0
while attempts < max_attempts:
try:
print(f"Fetching data for {company} (Attempt {attempts + 1})")
fundamentals_data, e = ek.get_data(
instruments=[company],
fields=["TR.RevenueActReportDate", "TR.F.StatementDate", *EXPORT_FIELDS],
parameters={
'SDate': '1940-01-01',
'EDate': datetime.now().strftime("%Y-%m-%d"),
'Frq': 'Y'
}
)
if e:
print(f"Error fetching data for {company}: {e}")
time.sleep(2) # Pause before retry
attempts += 1
continue
print(f"Saving data for {company}")
fundamentals_data.to_csv(file_pat
print(f"Finished processing for {company}. Moving to the next RIC.\n")
return
except Exception as e:
print(f"Failed to get market cap for {company} due to: {tb.format_exc()}")
attempts += 1
time.sleep(2)
for company in COMPANY:
process_single_company(company)
I tried:
- Batching the requests to process multiple companies or multiple fields at once.
- Processing fields one by one to handle local errors.
- Implementing rate limiting.
How can I speed up the process or maybe I am missing something and there is a better way to handle this amount of data? Or maybe any tips on how to better handle large volumes of data without hitting timeouts?
Thank you!
Best Answer
-
Thank you for reaching out to us.
The request can be timed out by the server. Typically the timed out can happen when the application requests a lot of data in one request. To avoid this issue, the application can reduce the number of items, fields, or date range in each request.
Moreover, you can contact your LSEG account team or sales team directly to discuss this kind of usage. The sales team may be able to suggest other methods that are more suitable for your requirements.
0
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 中文论坛