question

Upvotes
1 0 0 0

datastream API, relating to stock index.

using datastream API, how to get constituents of a stock index list, and then get the financial indicators of the stocks achieved.

for example, get the main financial indicators of the companies listed in S&P 500

#technology#contentpython apidatastream-api
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
Upvote
7k 21 3 6

Hi @tutan,

Have you had a look at the LSEG Developer Portal's Datastream page? In particular, the Documentation tab? I believe that the information you are after might be found there.
Else, I had a look into the Datastream Navigator to find the mnemonic that may link to S&P 500, and found "LS&PCOMP". Then reading the documentation, it looks like you need "|L" at the end of the mnemonic to get the constituent list:

import DatastreamPy as ds

# We can use our LSEG's Datastream API keys that allows us to be identified by Refinitiv's back-end services and enables us to request (and fetch) data: Credentials are placed in a text file so that it may be used in this code without showing it itself.
ds_username = open("Datastream_username.txt", "r")
ds_password = open("Datastream_password.txt", "r")

ds = ds.DataClient(
    config=None,
    username=str(ds_username.read()),
    password=str(ds_password.read()),
    proxies=None,
    sslVerify=None,
    sslCert=None)

# It is best to close the files we opened in order to make sure that we don't stop any other services/programs from accessing them if they need to.
ds_username.close()
ds_password.close()


# # Alternatively one can use the following:
# import getpass
# dsusername = input()
# dspassword = getpass.getpass()
# ds = dsws.Datastream(username = dsusername, password = dspassword)

ds.get_data(tickers='LS&PCOMP|L', fields =["MNEM"], kind=0)



Note that my credentials are placed in a text file so that it may be used in this code without showing it itself:
1726767722013.png


df_of_mnemonic = ds.get_data(tickers='LS&PCOMP|L', fields =["MNEM"], kind=0)
df_list = df_of_mnemonic.Value.to_list()
print(df_list)
ds.get_data(tickers=",".join(df_list[0:10]), fields =["P"], kind=0)


1726767977013.png



I'm not sure what you mean by "financial indicators"; do you have a field name in Datastream that refers to it?


1726767722013.png (3.3 KiB)
1726767977013.png (42.9 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.

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.