mrhappyasthma/IsThisStockGood

Sticker Price and Margin of Safety Price Always Show as Undefined

NaughtRobot opened this issue · 6 comments

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.

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.

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.

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

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:

  • Call the Query API with the ticker to see if there's a match
    • If a match is found, extract the ID from SecId
    • Issue a request to KeyRatios using the ID
      • If successful, extract all the PEs from the list of companyMetrics -> priceToEarningsRatio
      • Determine the max/min of this list of values

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.

Fixed in #60