Yahoo Finance API stock/ticker lookup only allowing exact match
Asked Answered
A

4

12

Until yesterday a query such as this http://autoc.finance.yahoo.com/autoc?query=a&callback=YAHOO.Finance.SymbolSuggest.ssCallback yielded a long list of fuzzy/broadmatch results for both ticker and company name.

Since today you are a.) required to specific region and language and b.) it is only yielding exact match results only for the ticker and not for the company name. Thus usually you get only one results back.

Thus for http://autoc.finance.yahoo.com/autoc?query=y&region=US&lang=en&callback=YAHOO.Finance.SymbolSuggest.ssCallback there's now only one result: YAHOO.Finance.SymbolSuggest.ssCallback({"ResultSet":{"Query":"a","Result":[{"symbol":"A","name":"Agilent Technologies Inc.","exch":"NYQ","type":"S","exchDisp":"NYSE","typeDisp":"EQUITY"}]}});

Any idea how to a.) broaden the match type and b.) include the company name as the searched field?

Antiphony answered 2/10, 2015 at 1:15 Comment(0)
S
21

The URL has now changed to this: http://d.yimg.com/aq/autoc?query=y&region=US&lang=en-US&callback=YAHOO.util.ScriptNodeDataSource.callbacks

Swane answered 5/10, 2015 at 8:4 Comment(9)
Hi, I'm just curious, how were you aware of this change? I rely on this API and this post saved me some serious trouble/headache.Skiles
@AllTheTime Glad it helped you and good question :) "Unfortunately" I saw that it didn't work by coincidence and googled to find a mention of the new URL. If you find a method to monitor it in a good way, please let me know :)Swane
@Swane I just started by catching 400 errors and sending an email to myself from the server when they happen so I can find out about them fasterSkiles
@AllTheTime Good idea :-)Swane
That just saved my life. Thank you so much! How did you find the corrected URL by the way?Collard
Man, you just saved my life (and my app)! Thank you so much !Hendeca
You can skip the callback parameter, i.e. d.yimg.com/aq/autoc?query=y&region=US&lang=en-US and this will return you only the JSON.Danielson
does anyone know how to add parameters to this call? For instance, I only want results from the exchanges: NAS and NYQ. I can't find any documentationOrdinarily
Why is this not working anymore? Until recently it did. As of today I get a "Will be right back ... ". Will it really be?Grizelda
C
6

The following works (the returned data stream has lots of escape characters):

http://autoc.finance.yahoo.com/autoc?query=alphabet&region=EU&lang=en-GB

Or expanded in the YQL Console:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Fautoc.finance.yahoo.com%2Fautoc%3Fquery%3Dalphabet%26region%3DEU%26lang%3Den-GB'&format=json&callback=
Culbert answered 12/5, 2016 at 12:48 Comment(2)
the region choice doesn't seem to have any effect.Zincograph
Does anyone know how to add parameters to this call? For instance, I only want results from the exchanges: NAS and NYQ. I can't find any documentationOrdinarily
K
0

Shameless Plug

When I was building an app that required stock symbol/company lookup, I tried a few options, and none were very good. I took what I built, and made it public: https://www.stocksearchapi.com

UPDATE I took this offline due to lack of interest

Kessinger answered 21/1, 2017 at 20:22 Comment(2)
@JunchaoGu Took offline due to lack of interestKessinger
I think markit took down their api as well. recently I am trying to work a nice solution for this though. Other than yahoo finance, I did not find any other good candidate. maybe i will try google search company name as wellOctodecillion
C
0

I found some of the above URL inactive. You can check

https://query2.finance.yahoo.com/v1/finance/search

Pythonic way to extract ticker lookup is


def getTicker(company_name):
    yfinance = "https://query2.finance.yahoo.com/v1/finance/search"
    user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
    params = {"q": company_name, "quotes_count": 1, "country": "United States"}

    res = requests.get(url=yfinance, params=params, headers={'User-Agent': user_agent})
    data = res.json()

    company_code = data['quotes'][0]['symbol']
    return company_code

Credit to https://gist.github.com/bruhbruhroblox/dd9d981c8c37983f61e423a45085e063

Celisse answered 31/1, 2023 at 6:13 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.