search
Package search provides Yahoo Finance search functionality.
Overview
The search package allows you to search for stock symbols, company names, and other financial assets on Yahoo Finance. It also retrieves related news articles, lists, and research reports.
Basic Usage
s, err := search.New()
if err != nil {
log.Fatal(err)
}
defer s.Close()
result, err := s.Search("AAPL")
if err != nil {
log.Fatal(err)
}
for _, quote := range result.Quotes {
fmt.Printf("%s: %s (%s)\n", quote.Symbol, quote.ShortName, quote.Exchange)
}
Search Methods
The Search struct provides the following methods:
- Search.Search: Simple search with default parameters
- Search.SearchWithParams: Search with custom parameters
- Search.Quotes: Get only quote results
- Search.News: Get only news results
Search Parameters
Use [models.SearchParams] to customize your search:
params := models.SearchParams{
Query: "Apple",
MaxResults: 10,
NewsCount: 5,
EnableFuzzyQuery: true,
}
result, err := s.SearchWithParams(params)
Thread Safety
All Search methods are safe for concurrent use from multiple goroutines.
Index
- type Option
- func WithClient(c *client.Client) Option
- type Search
- func New(opts ...Option) (*Search, error)
- func (s *Search) Close()
- func (s *Search) News(query string, newsCount int) ([]models.SearchNews, error)
- func (s *Search) Quotes(query string, maxResults int) ([]models.SearchQuote, error)
- func (s *Search) Search(query string) (*models.SearchResult, error)
- func (s *Search) SearchWithParams(params models.SearchParams) (*models.SearchResult, error)
type Option
Option is a function that configures a Search instance.
func WithClient
WithClient sets a custom HTTP client.
type Search
Search provides Yahoo Finance search functionality.
func New
New creates a new Search instance.
Example:
func (*Search) Close
Close releases resources used by the Search instance.
func (*Search) News
News returns only the news results for a search query.
Example:
news, err := s.News("Apple", 10)
for _, n := range news {
fmt.Printf("%s: %s\n", n.Publisher, n.Title)
}
func (*Search) Quotes
Quotes returns only the quote results for a search query.
Example:
quotes, err := s.Quotes("Apple", 10)
for _, q := range quotes {
fmt.Printf("%s: %s\n", q.Symbol, q.ShortName)
}
func (*Search) Search
Search searches for symbols and returns matching quotes.
This is a convenience method that uses default parameters.
Example:
result, err := s.Search("AAPL")
if err != nil {
log.Fatal(err)
}
for _, quote := range result.Quotes {
fmt.Printf("%s: %s\n", quote.Symbol, quote.ShortName)
}
func (*Search) SearchWithParams
SearchWithParams searches with custom parameters.
Example: