mrhappyasthma / IsThisStockGood

A tool for evaluating companies using the Rule #1 investing principles.
http://www.isthisstockgood.com
22 stars 10 forks source link

Sticker Price and Margin of Safety Price Always Show as Undefined #57

Closed NaughtRobot closed 1 year ago

NaughtRobot commented 1 year ago

The calculations for both Sticker Price and Margin of Safety Price can't be determined because the URL used to gather the 5-Yeah High and 5-Year Low P/E no longer works.

https://www.msn.com/en-us/money/stockdetails/analysis?symbol= will return a 200 status code, but there isn't anything within the returned data.

mrhappyasthma commented 1 year ago

Well that's disappointing. MSN whyyyy.

We'll need to find a new data source or just fallback to their 3-year that they provide. Which isn't ideal but may be the best short term solution.

mrhappyasthma commented 1 year ago

It looks like this data is actually still available and fortunately doesn't need any API key. It's used to powers their historical chart: https://i.imgur.com/hx4aeZh.png.

We could still compute the 5-year min/max by extracting all those values from the json and determining the max and min ourselves.

URL example: https://services.bingapis.com/contentservices-finance.financedataservice/api/v1/KeyRatios?stockId=a1u3p2 Pretty-printed json output: https://pastebin.com/raw/c1ZRJe22

The tricky thing is that they use a stockId value, rather than just the ticker symbol. And I haven't yet found a good way to convert between the two. Even the primary URLs (e.g. www.msn.com/en-us/money/stockdetails/fi-a1u3p2) don't use the ticker symbol directly.

If we can find a way to issue a query to determine the stockId for a given symbol, then we may be able to bring back the exact same dataset as before.

mrhappyasthma commented 1 year ago

Not sure if it's useful yet, but the ID appears to be the suffix after the hyphen from the main URL:

e.g. www.msn.com/en-ph/money/stockdetails/fi- a1u3p2

but I still haven't stumbled upon a good way to send a ticker and have it resolve to this URL

mrhappyasthma commented 1 year ago

Ohhh looks like we may be able to use this: https://services.bingapis.com/contentservices-finance.csautosuggest/api/v1/Query?query=<ticker>. This is the request they issue for auto-completion suggestions whenever you are typing in the ticker-symbol search box

e.g. https://services.bingapis.com/contentservices-finance.csautosuggest/api/v1/Query?query=goog

The ID can be found with the SecId key under the appropriate stock.

So we may be able to do something like:

mrhappyasthma commented 1 year ago

The downside to this approach is that it requires a series of two, sequential requests. Which is not great for latency. (Although we could cache these IDs for some reasonable amount of time, since they are unlikely to change.)

The benefit is that we actually get (at least) the same data as before and (in some cases) may have more than 5 years of data available if we ever wanted to factor that in.

mrhappyasthma commented 1 year ago

Fixed in https://github.com/mrhappyasthma/IsThisStockGood/pull/60