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


7 1 1 6

news.get_headlines - how to include column for RICS


I am using Refinitiv Data library to collect news articles in Python, which is working fine.

Any idea of how I can return the list of RICS that the article relates to, just like News Monitor does in Eikon Desktop. I've included a snapshot of what I need below.

Here is my current code:

reg_df = pd.DataFrame(columns=['timestamp_API', 'RIC', 'headline', 'story', 'storyid'])
headlines = rd.news.get_headlines('R:TSLA.O', 
                                  end='2023-11-08T23:59:00', #API is 1hr behind the UK
                                  count = 100)
headlines = headlines.reset_index()
temp_df = pd.DataFrame(columns=['timestamp_API', 'headline', 'story', 'storyid'])
for index, row in headlines.iterrows():    
    newsText = rd.news.get_story(row['storyId'], format=rd.news.Format.TEXT) #get the news story
    temp_df.loc[index] = [row['versionCreated'], row['headline'], newsText, row['storyId']]
company_news_df = pd.concat([reg_df, temp_df], ignore_index=True)

A snapshot of what I'm after in the dataframe is attached.

Any help greatly appreciated.


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.

1 Answer

· Write an Answer
10.5k 19 6 9

@di.ti Thanks for your question - so to do this you would need to use the RD Library - which is our latest library providing access to EIkon/Workspace services as well as newer services on the Data Platform. You can use both RD services as well as the Eikon Data API from the same library. First you need to install the library:

pip install refinitiv-data

once this is installed you can:

import refinitiv.data as rd
# import refinitiv.data.eikon as ek #you can also use the Eikon Data API from here
from refinitiv.data.content import news
from IPython.display import HTML
import pandas as pd
# ek.set_app_key('Your_AppKey_Here')
dNow = datetime.now().date()
maxenddate = dNow - timedelta(days=7) #upto months=15
compNews = pd.DataFrame()
riclist = ['VOD.L','HD','MSFT.O'] # can also use Peers, Customers, Suppliers, Monitor, Portfolio to build universe

for ric in riclist:
        cHeadlines = rd.news.get_headlines("R:" + ric + " AND Language:LEN", start= str(dNow), end = str(maxenddate), count = 10)
        cHeadlines['cRIC'] = ric
        if len(compNews):
            compNews = pd.concat([compNews,cHeadlines])
            compNews = cHeadlines
    except Exception:


Now you need to use the delivery layer of the RD Library to make an endpoint request to the news story endpoint to access additional metadata such as story text, topic codes etc. We will get all the topic codes and then extract the PermIDs that were tagged for this article.

# For each news headline get story text and topic codes

baseurl = "/data/news/v1/stories/"
fullcodelist = pd.DataFrame()
compNews['storyText'] = str()
compNews['q_codes'] = str()
compNews['sentiment'] = str()
compNews['cos_mentioned'] = str()

for i, uri in enumerate(compNews['storyId']):
    request_definition = rd.delivery.endpoint_request.Definition(
        url = baseurl + uri,
        method = rd.delivery.endpoint_request.RequestMethod.GET
    response = request_definition.get_data()
    rawr = response.data.raw
    if 'newsItem' in rawr.keys():
        compNews['storyText'][i] = rawr['newsItem']['contentSet']['inlineData']['$']
        topics = rawr['newsItem']['contentMeta']['subject']
        compNews['q_codes'][i] = [d['_qcode'] for d in topics]
        compNews['cos_mentioned'][i] = [x for x in compNews['q_codes'][i] if x.startswith("P:")]


So in the column compNew['cos_mentioned'] we have a list of PermIDs that were mentioned in the article. You want to use PermIDs as these will include private companies that may not have a RIC. You can then pass the PermIDs to other functions such as rd.get_data() to get additional reference and fundamental information. I hope this can help.

1699618335706.png (322.5 KiB)
1699618763311.png (185.3 KiB)
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.

Hi @jason.ramchandani01

You can also use the refinitiv library to go through the dataframe with story ids to get the RIC codes:

from refinitiv.data.content import news
storyid = 'urn:newsml:reuters.com:20231110:nRTV8tfcw0:4'
story_data = news.story.Definition(storyid).get_data()

rics = [i['_qcode'][2:] for i in story_data._raw['newsItem']['assert'] if i['_qcode'].startswith("R:")]

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.