question

Upvotes
Accepted
3 1 2 5

Problem in converting ticker to RIC by refinitiv.data package

Hi, I encountered a problem in converting tickers to RICs in Refinitiv.

1. However, before I move to next step, I found I suddenly have problems in retrieving data from refinitiv. After I set my app key and opened session by rd, there is always an error showing as follows:

An error occurred while requesting URL('http://localhost:9000/api/rdp/discovery/search/v1/lookup').

RemoteProtocolError("illegal status line: bytearray(b'\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x7fn\\x01oding: gzip, deflate')")

.......

h11._util.RemoteProtocolError: illegal status line: bytearray(b'\xff\x00\x00\x00\x00\x00\x00\x00\x01\x7fn\x01oding: gzip, deflate')

.......

httpcore.RemoteProtocolError: illegal status line: bytearray(b'\xff\x00\x00\x00\x00\x00\x00\x00\x01\x7fn\x01oding: gzip, deflate')

2. For the retrieving data code, below is the code. I would be very grateful if someone can help me out.

import pandas as pd
import refinitiv.data as rd
from refinitiv.data.content import symbol_conversion

def RefinitivRetriever(Ticker):
    rd.open_session()
    converted = []

    Refinitiv_Info = symbol_conversion.Definition(
        symbols = Ticker,
        from_symbol_type = symbol_conversion.SymbolTypes.TICKER_SYMBOL,
        to_symbol_types = [
            symbol_conversion.SymbolTypes.RIC
        ],
    ).get_data()
    # This step is to check if the conversion is successful. If not, fill in with an empty string.    
    for t in Ticker:
        try:
            converted = converted.append(Refinitiv_Info.data.raw['Matches'][t]['RIC'])
        except KeyError:
            converted = converted.append('')
    
    # Return a dataframe with two columns, first one RIC list, while the second one Company Market Cap
    RICs = Refinitiv_Info.data.df['RIC'].tolist()
    MarketCap = rd.get_data(RICs, fields = ['TR.CompanyMarketCap'])
    MarketCap.columns = ['RIC', 'MarketCap']

    rd.close_session()
pythonrefinitiv-dataplatform-eikon#technologypython apiricsrefinitiv-data-platform-libraries
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
Upvotes
Accepted
83.1k 281 53 77

@CharlesYan

Thank you for reaching out to us.

I can run the code properly but I think it is not good to open and close the RD session everytime the application calls the RefinitivRetriever method.

The RD session can be opened at the begining of the application and then closed at the end of the application.

Therefore, I modified the code to look like this:

import pandas as pd
import refinitiv.data as rd
from refinitiv.data.content import symbol_conversion


rd.open_session()

def RefinitivRetriever(Ticker):
    
    converted = []
 
    Refinitiv_Info = symbol_conversion.Definition(
        symbols = Ticker,
        from_symbol_type = symbol_conversion.SymbolTypes.TICKER_SYMBOL,
        to_symbol_types = [
            symbol_conversion.SymbolTypes.RIC
        ],
    ).get_data()
    
    # This step is to check if the conversion is successful. If not, fill in with an empty string.    
    for t in Ticker:
        print(t)
        try:            
            converted.append(Refinitiv_Info.data.raw['Matches'][t]['RIC'])            
        except KeyError:
            converted.append('')
    
    # Return a dataframe with two columns, first one RIC list, while the second one Company Market Cap
    RICs = Refinitiv_Info.data.df['RIC'].tolist()
    MarketCap = rd.get_data(RICs, fields = ['TR.CompanyMarketCap'])
    MarketCap.columns = ['RIC', 'MarketCap']
    print(MarketCap) 
   
    
    
RefinitivRetriever(["IBM","PTT"])
RefinitivRetriever(["VOD","GOOG"])


rd.close_session()

How did you call the RefinitivRetriever method?

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, Jiraponse. Here is an exception. If you try to retrieve 'SNCRL.O', there will be an error. I will be grateful if you can help me out.

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.