Fetching all companies in an index

Hide code cell content
import refinitiv.data as rd

rd.open_session()
/home/runner/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_access_layer/session.py:71:FutureWarning: 
You open a platform session using the default value of the signon_control parameter (signon_control=True).
In future library version v2.0, this default will be changed to False.
If you want to keep the same behavior as today, you will need to set the signon_control parameter to True either in the library configuration file
({'sessions':{'platform':{'your_session_name':{'signon_control':true}}}}) or in your code where you create the Platform Session.
These alternative options are already supported in the current version of the library.
[Error 400] - {'error': 'access_denied', 'error_description': 'Account locked out due to provide incorrect password.'}
<refinitiv.data.session.Definition object at 0x7f34b45a5510 {name='rdp'}>

You can use the Refinitiv Data Library for Python to retrieve metadata about all of the companies in a stock index.

To do so, pass the index’s Refinitiv Instrument Code with a 0# prefix to the fundamental_and_reference component of package’s content submodule.

The method requires that you specify at least one field to retrieve for each company, in addition to its code. Here’s how to retrieve the name and ticket symbol of each of the 30 entries in the Dow Jones Industrial Average:

rd.content.fundamental_and_reference.Definition(
    universe=["0#.DJI"],
    fields=[
        "TR.CommonName",
        "TR.TickerSymbol"
    ],
).get_data().data.df
Session is not opened. Can't send any request
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 7
      1 rd.content.fundamental_and_reference.Definition(
      2     universe=["0#.DJI"],
      3     fields=[
      4         "TR.CommonName",
      5         "TR.TickerSymbol"
      6     ],
----> 7 ).get_data().data.df

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/content/fundamental_and_reference/_definition.py:269, in Definition.get_data(self, session, on_response)
    266         ticket = raw.get("ticket")
    268 else:
--> 269     response = super().get_data(session, on_response)
    271 return response

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/content/_content_provider_layer.py:58, in ContentUsageLoggerMixin.get_data(self, session, on_response)
     51 # Library usage logging
     52 get_usage_logger().log_func(
     53     name=f"{ModuleName.CONTENT}.{self._USAGE_CLS_NAME}.get_data",
     54     func_path=f"{self.__class__.__module__}.{self.__class__.__qualname__}.get_data",
     55     kwargs={**self._kwargs},
     56     desc={FilterType.SYNC, FilterType.LAYER_CONTENT},
     57 )
---> 58 return super().get_data(session, on_response)

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/delivery/_data/_data_provider_layer.py:149, in DataProviderLayer.get_data(self, session, on_response)
    133 """
    134 Sends a request to the client file store to retrieve the previously defined data.
    135 
   (...)
    146 
    147 """
    148 session = get_valid_session(session)
--> 149 response = get_data(self._data_type, self._provider, session, **self._kwargs)
    150 if on_response is not None:
    151     warnings.warn(
    152         "Avoid using on_response for get_data method, it will be removed in future library version v2.0.",
    153         category=FutureWarning,
    154     )

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/delivery/_data/_data_provider_layer.py:51, in get_data(data_type, provider, session, **kwargs)
     44 # Library usage logging
     45 get_usage_logger().log_func(
     46     name=f"{ModuleName.DELIVERY}.{DataProviderLayer._USAGE_CLS_NAME}.get_data",
     47     func_path=f"{DataProviderLayer.__module__}.{DataProviderLayer.__qualname__}.get_data",
     48     kwargs={"url": url, "auto_retry": auto_retry, **kwargs},
     49     desc={FilterType.SYNC, FilterType.LAYER_DELIVERY},
     50 )
---> 51 response = provider.get_data(session, url, auto_retry=auto_retry, **kwargs)
     52 return response

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/delivery/_data/_data_provider.py:78, in DataProvider.get_data(self, session, *args, **kwargs)
     77 def get_data(self, session: "Session", *args, **kwargs) -> Response:
---> 78     raise_if_closed(session)
     79     request = self.request.create(session, *args, **kwargs)
     80     raw_response = self.connection.send(request, session, *args, **kwargs)

File ~/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_core/session/tools.py:37, in raise_if_closed(session)
     35 error_message = "Session is not opened. Can't send any request"
     36 session.error(error_message)
---> 37 raise ValueError(error_message)

ValueError: Session is not opened. Can't send any request

Note

In Refinitiv terminology, the 0# prefix is known as a “chain.” It is used to identify a group of instruments that share a common characteristic, such as being part of an index.

Hide code cell content
rd.close_session()