Historical closing price of stocks using API

I have a dynamic set of stocks (RICs) for which I want to get the closing price data from say last 6 years on daily weekly and monthly level in USD. How Do I do that using LSEG APIs.
Answers
-
Thank you for reaching out to us.
You can use the get_history method in the LSEG Data Library for Python to retrieve historical data.
For example:
df = ld.get_history( universe = ["IBM.N","MSFT.O","GOOG.O"], start= "2024-01-01", end = "2025-03-01", interval="daily") df
If you don't specify the fields parameter, it will return all available fields. Otherwise, you can specify the required fields in fields parameter, such as TRDPRC_1.
df = ld.get_history( universe = ["IBM.N","MSFT.O","GOOG.O"], fields = ["TRDPRC_1"], start= "2024-01-01", end = "2025-03-01", interval="daily") df
You can change the start, end, and interval parameters and use the help command to list all parameters.
help(ld.get_history)
The examples are also available on GitHub.
0 -
Thanks for the response @jirapongse. How do I make sure these closing prices are in USD?
0 -
I forgot about the currency. In this case, you can use the TR.ClosePrice field.
df = ld.get_history( universe = ["IBM.N","MSFT.O","GOOG.O","PTT.BK"], fields = ["TR.ClosePrice(Curn=USD)"], start= "2024-01-01", end = "2025-03-01", interval="daily") df
0 -
Thanks again @Jirapongse .
We are not there yet.
The following 2 are the excel formulas that I am using so far and want to now use APIs to get these data points.
———————————-——
1) DSGRID(MASTER_LIST!$A3:$B3000,"1000*X(RI)~U$/MSACWF$(RI)","2022-01-01","","D","CustomHeader=true;CustHeaderDatatypes=RIC;RowHeader=true;ColHeader=true;DispSeriesDescription=false;YearlyTSFormat=false;QuarterlyTSFormat=false;Sym=RIC;MonthlyTSFormat=True","")
2) @DSGRID(MASTER_LIST!$A3:$B3000,"X(RI)~U$","2022-01-01","","D","CustomHeader=true;CustHeaderDatatypes=RIC;RowHeader=true;ColHeader=true;DispSeriesDescription=false;YearlyTSFormat=false;QuarterlyTSFormat=false;Sym=RIC;MonthlyTSFormat=False","")
———————————-——With respect to the above two
a) 1000*X(RI)~U$/MSACWF$(RI) : Here I believe we are trying to get a relative price of the constituents (in master_list a3-b3000) against an index.b) X(RI)~U$ : Here the absolute prices for the same instruments.
This is exactly what I am looking for.
My thought wasdf = ld.get_history( universe = ["IBM.N","MSFT.O","GOOG.O","PTT.BK"], fields = ["TR.ClosePrice(Curn=USD)"], start= "2024-01-01", end = "2025-03-01", interval="daily")df
For example will yield the answer atleast for the point I mentioned above in 2nd, but It wasnt really matching up.
Can we try to convert 1) and 2) i.e. mentioned excel formulas into python code?0 -
DSGRID is a Datastream product. You can use the Datastream Web Service to retrieve data.
The DatastreamPy Python library is available on Pypi.
The code looks like this:
df = ds.get_data(tickers="@GOOGL,U:IBM", fields = [ "1000*X(RI)~U$/MSACWF$(RI)", "X(RI)~U$"], kind=1, freq='D', start="2022-01-01") df
0 -
I imagine that pricing data that you shared works on the mnemonics as the inputs, Correct? I remember in eikon there was a direct way to convert them from one symbol type to another, couldnt really find a way to convert RICs to Mnemonics in LSEG.data. Any workaround for that?
I also tried to work with :
response = symbol_conversion.Definition(
symbols=["MSFT.O", "AAPL.O", "GOOG.O", "IBM.N"]
).get_data()response.data.df
This doesnt rwally give mnemonics.
2) For an entirely different problem,
I am interested in getting the following data :
(RIC', 'NAME', 'SECD', 'WTIDX', 'ISOCUR', 'MSCNSN', 'MSCNIGN', 'MSCNIN', 'MSCNSIN', 'MSCTRYN', 'WC06028'
)
I am able to get it on the list level as dictated by "LMSACWF0424", I want to replicate the same on stock (RIC) level
df=ds.get_data(tickers='LMSACWF0424', fields=('RIC', 'NAME', 'SECD', 'WTIDX', 'ISOCUR', 'MSCNSN', 'MSCNIGN', 'MSCNIN', 'MSCNSIN', 'MSCTRYN', 'WC06028'), kind=0)
Please suggest the best ways to do that.0 -
It also works with RICs by enclosing a RIC with the <…>. For example:
df = ds.get_data(tickers="<MSFT.O>,<AAPL.O>,<GOOG.O>,<IBM.N>", fields = [ "1000*X(RI)~U$/MSACWF$(RI)", "X(RI)~U$"], kind=1, freq='D', start="2022-01-01") df
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 684 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 249 ETA
- 554 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 643 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 192 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛