Skip to content

Instantly share code, notes, and snippets.

@jimmysitu
Last active November 5, 2023 09:54
Show Gist options
  • Save jimmysitu/161d2effc0d3b17e401fdafa6e5b615d to your computer and use it in GitHub Desktop.
Save jimmysitu/161d2effc0d3b17e401fdafa6e5b615d to your computer and use it in GitHub Desktop.
morningstar.com API

morningstar.com API

  • Get key ratio, return csv format file
http://financials.morningstar.com/ajax/exportKR2CSV.html?t=<market>:<stock>

Market

  • XHKG: Hong Kong Stock Exchange
  • XASE: American Stock Exchange
  • XNAS: Nasdaq Stock Exchange
  • XNYS: New York Stock Exchange
  • XSHE: ShenZhen Stock Exchange
  • XSHG: Shanghai Stock Exchange

Example, get Tencent Holdings Ltd from HongKong market. http://financials.morningstar.com/ajax/exportKR2CSV.html?t=XHKG:000700

  • Get financial statment, return csv format file
http://financials.morningstar.com/ajax/ReportProcess4CSV.html?t=<market>:<stock>&reportType=<is|cf|bs>&period=<12|3>&dataType=<A|R>&order=<asc|desc>&denominatorView=<raw|percentage|decimal>&columnYear=5&number=3
  • reportType: is = Income Statement, cf = Cash Flow, bs = Balance Sheet
  • period: 12 for annual reporting, 3 for quarterly reporting
  • dataType: this doesn't seem to change and is always A
  • order: asc or desc (ascending or descending)
  • columnYear: 5 or 10 are the only two values supported, 10 years report need register
  • number: The units of the response data. 1 = None 2 = Thousands 3 = Millions 4 = Billions
  • Get price ratio, return html

Get price ratio history

http://financials.morningstar.com/valuate/valuation-history.action?&t=<market>:<stock>&type=price-earnings

Get current price ratio

http://financials.morningstar.com/valuate/current-valuation-list.action?&t=<market>:<stock>

Get forward price ratio

http://financials.morningstar.com/valuate/forward-valuation-list.action?&t=<market>:<stock>
  • Get history price, return json format data
http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=<maarket>:<stock>&showVol=true&dtype=his&f=d&range=<startDate>|<endDate>
  • f: m = month, d = day
  • startData, endData: YYYY-M-D
@urbanskalar
Copy link

urbanskalar commented Sep 20, 2021

I tried: http://globalquote.morningstar.com/globalcomponent/RealtimeHistoricalStockData.ashx?ticker=XNAS:AMZN&showVol=true&dtype=his&f=d&range=2020-12-31|2021-03-31

And I get a 502 error?

This one doesn't work for me either, but I found a different link which uses csv format instead of json:

http://performance.morningstar.com/perform/Performance/stock/exportStockPrice.action?t=<market:ticker>&pd=max&freq=<frequency>&sd=&ed=&pg=0&culture=en-US&cur=USD')

where market is as mentioned above:

XHKG: Hong Kong Stock Exchange
XASE: American Stock Exchange
XNAS: Nasdaq Stock Exchange
XNYS: New York Stock Exchange
XSHE: ShenZhen Stock Exchange
XSHG: Shanghai Stock Exchange

frequency is:

d for daily
w for weekly
m for monthly
q for quarterly
a for annualy

and I'm pretty sure you know what ticker is.

I didn't play with other parameters, but I guess you could set range for "pd" instead of current value "max". If you want to do more research on this you can use Browser Console (on firefox) and pres export button with different parameters on this link and observe urls that pup up.

@lamberbee
Copy link

Working fine for stocks but what about funds. Just giving in the ISIN or M* ID only gives an empty file.
For example:
ISIN: IE00BYYLQ314
ID: F00000Y93D

@Jaykingamez
Copy link

Jaykingamez commented Mar 12, 2022

Some notes for my future self:

All done in Postman

This works for all stocks, just need to input the ticker and market

http://financials.morningstar.com/ajax/exportKR2CSV.html?t=market:ticker

For instance, if one searches cd projekt red on Morningstar
https://www.morningstar.com/stocks/xwar/cdr/analysis
XWAR is the market, and cdr is the ticker

http://financials.morningstar.com/ajax/exportKR2CSV.html?t=xwar:cdr
This gives you ten years of financial data.

However, we also need to attach the Referer header.

Set the "Referer" header to this, appropriated from an above answer, and you'll get 10 years of financial data.
https://financials.morningstar.com/ratios/r.html?t=AAPL&culture=en&platform=sal

However, the data is all in CSV. So need to do some string manipulation to get what you want.

@orelhochenboym
Copy link

Cant understand this. Nothing works.

I am just trying to get fundamental data like revenue, net income etc.

what url do I query from? Nothing seems to be working...

@urbanskalar
Copy link

urbanskalar commented Feb 12, 2023

Hey! I'm not sure where your problem is and I haven't used this for a while now so I wouldn't know. Maybe Morningstar changed something and it's not working anymore. If it helps, below is a link to the repository where I implemented all of the API calls I found avaliable at the time. You can play with those to see if something doesn't work anymore. Last time I tried all of them worked.

https://github.com/urbanskalar/Morningstar-API

@jimmysitu
Copy link
Author

Hi, All

This gist is out of date and not working anymore. For those want to grab finance data from morningstar.com,
please try the new project msfinance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment