Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Search Utility #1949

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

avhagedorn
Copy link

@avhagedorn avhagedorn commented May 27, 2024

Generalizes isin search to support new types of search queries.

Use case:
I would like to be able to keep all yahoo finance code contained in the yfinance lib. Right now to perform a ticker search, I have to perform the following in my application:

    response = requests.get(
        "https://query1.finance.yahoo.com/v1/finance/search",
        params={"q": q, "newsCount": 0, "quotesCount": 5, "enableFuzzyQuery": False},
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"
        },
    )

Related to #837

@ValueRaider
Copy link
Collaborator

Give an example use code, so people can try out.

@avhagedorn
Copy link
Author

Sorry, by example use code do you mean providing a snippet here or adding to the README?

In either case, here's a quick snippet.

import json
from yfinance.utils import search

user_input = input("Enter a ticker query: ")
search_result = search(user_input, newsCount=0)            # Just search for tickers
search_result_quotes = search_result.get("quotes", [])

print(json.dumps(search_result_quotes, indent=2))           # Pretty print

Input

Enter a ticker query: apple

Output

[
  {
    "exchange": "NMS",
    "shortname": "Apple Inc.",
    "quoteType": "EQUITY",
    "symbol": "AAPL",
    ...
  },
  ...
]

@ValueRaider
Copy link
Collaborator

Just so I understand the use case correctly - how is this different to Ticker.news? Should Ticker.news be changed to use your code.

@avhagedorn
Copy link
Author

This use case targets searching for tickers - the underlying API does also fetch related news articles, but the primary motivation behind this is some kind of ticker search functionality. I should also note that I haven't found anything in the library currently for this use case, but I could be missing something. Hope that clears this up!

@ValueRaider
Copy link
Collaborator

def get_news(self, proxy=None) -> list:

@petey9891
Copy link

@ValueRaider, the get_news function currently only returns the news list and excludes the quotes list in the /search response. Having a search utility function would be a valuable addition and filtering the data to show just the quotes would help eliminate redundancy with get_news.

@ValueRaider
Copy link
Collaborator

would help eliminate redundancy with get_news

Agree. I wasn't rejecting the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants