Japanese Investor Briefs in News - Part 1
Introduction
Refinitiv Japanese Investor Briefs is a dedicated Japanese-language service which provides a subset of Reuters Briefs stories which are translated.
Our Task "in a Nutshell"
Our primary interest is to absorb programmatically, or to filter, only the news that are marked with NP:RINBX code.
Therefore, a query expression in the simplest form could look like this, or this query stanza can also be as part of a more complex query filter:
GET https://api.refinitiv.com/data/news/{{RDP_VERSTION_NEWS}}/headlines?query=NP:RINBX&limit=50&dateFrom=2021-10-12T00:00:00Z&dateTo=2021-10-20T23:59:59Z
We plan to go over some of the most common use cases for absorbing Japanese Investor Briefs:
- From RDP News service
- Python jupyter notebook
- Postman request collection
- Using SQS queues in Python script
- Using realtime streaming service with Refinitiv-Realtime Optimized in python
Integration with Refinitiv Data Platform News Service
1. Request Japanese Investor Briefs headlines, query reflects the required filtering criteria
2. Requesting stories per selected headlines
Let us first examine an ease of use approach, using Refinitiv Data Library Python. The link to learning more about RD Library python is included in References section at the end of this artcile.
Japanese Investor Briefs with Refinitiv Data Library Python
We include the required modules, setup the credentials, next, we open an RDP session and request japanse briefs headlines:
response = news.headlines.Definition(
query="NP:RINBX and LJA AND G:6J"
).get_data()
response.data.df
in this example we are looking at
Japanese Briefs (NP:RINBX) in Japanese language (LJA) related to United States (G:6J)
and our results in response Pandas dataframe reflect the requested:
next we can request the first story:
response2 = news.story.Definition(response.data.df['storyId'][0]).get_data() #"urn:newsml:reuters.com:20211003:nNRAgvhyiu:1").get_data()
#print(response2.data.raw)
if 'News Alert' in str(response2.data.raw):
print('<<<This is an ALERT>>>')
else:
print('TITLE: ',response2.data.story.title, '\n')
print(response2.data.story.content)
and the output will reflect the first story of the result:
however, most commonly, we wish to iterate over the headlines and retrieve all the stories that match the criteria:
count = 0;
for storyIdIter in response.data.df['storyId']:
print('Story ID #'+str(count)+' is : '+storyIdIter)
response3 = news.story.Definition(storyIdIter).get_data()
if 'News Alert' in str(response3.data.raw):
print('<<<This is an ALERT>>>')
else:
print('TITLE: ',response3.data.story.title, '\n')
print(response3.data.story.content)
print('---------------------------------------------')
count = count+1
resulting in output:
Japanese Investor Briefs with Postman
This is analogous straightforward retrieval per required criteria.
RDP News Japanese Briefs collection (the link to download it from GitHub is included in References section) consists from just 3 requests:
- Get RDP Access Token
- Get Headlines and Stories for Japanese Briefs (in Japanese language and related to United States)
- Get Story Per StoryId
Postman post-request tests and collection runner are used as a glue between the discrete requests, to enact the continuous run and to retrieve all the stories per criteria.
- Get RDP Access Token request picks up credentials from Postman environment, requests and obtains an access token and stores it back into Postman environment
- Get Headlines and Stories For Japanese Briefs, as reflected in the name, requests the stories, from RDP news, per required criteria:
GET https://api.refinitiv.com/data/news/{{RDP_VERSTION_NEWS}}/headlines?query=NP:RINBX and LJA AND G:6J&imit=50&dateFrom=2021-10-21T00:00:00Z&dateTo=2022-09-21T23:59:59Z
while in it's post-request test, we prepare to retrieve stories based on the storyIds contained in the current request's results that we store into Postman environment:
var jsonData = pm.response.json();
var arrStoryIds = [];
for(let i = 0; i < jsonData.data.length; i++) {
// console.log(jsonData.data[i].storyId)
arrStoryIds[i] = jsonData.data[i].storyId;
}
console.log('StoryIDs length='+arrStoryIds.length+',\n storyIDs='+arrStoryIds);
//console.log('StoryIDs 7th-'+arrStoryIds[7])
postman.setEnvironmentVariable("STORY_IDS", JSON.stringify(arrStoryIds));
postman.setEnvironmentVariable("CURRENT_ID", 0);
GET https://api.refinitiv.com/data/news/{{RDP_VERSTION_NEWS}}/stories/{{CURRENT_STORY_ID}}
but also in it's post-request test it will help us iterate over to the next StoryId and trigger the same request with it:
let storyIds = JSON.parse(postman.getEnvironmentVariable("STORY_IDS"));
let currentId = Number(postman.getEnvironmentVariable("CURRENT_ID"));
console.log('Current story ID ='+ storyIds[currentId])
var jsonData = pm.response.json();
// pretty print to console is very costly/slow, so unless required, keep it commented out
console.log('Current story ='+ JSON.stringify(jsonData))//,null, 2))
let nextCurrentId = currentId + 1
if (nextCurrentId < storyIds.length) {
postman.setEnvironmentVariable("CURRENT_ID", nextCurrentId);
postman.setNextRequest("Get Story per StoryId");
console.log("nextCurrentId="+nextCurrentId)
} else {
postman.setNextRequest(null)
console.log('This was the last story<<<>>>')
}
As we trigger Run collection on this collection
we see the progress of the collection run on the main pane:
and additionally on Postman console we see and examine every detail of the run:
we continue this discussion with Japanese Investor Briefs in News - Part 2, going over Realtime subscription and RDP with SQS queue.
References
- Article code on GihTub: Refinitiv-API-Samples/Article.RDP.Python.JapaneseInvestorBriefsInNews
- Refintiv Data Library Python: https://developers.refinitiv.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-library-for-python
- Postman Downloads: https://www.postman.com/downloads/
- Part 2 of the article: https://developers.refinitiv.com/en/article-catalog/article/japanese-investor-briefs-in-news-part-2