lookup
Package lookup provides Yahoo Finance ticker lookup functionality.
Overview
The lookup package allows searching for financial instruments (stocks, ETFs, mutual funds, indices, futures, currencies, and cryptocurrencies) by query string. This is useful for finding ticker symbols when you know the company name or a partial symbol.
Unlike the search package which provides general search across news, lists, and research, lookup is specifically designed for finding ticker symbols with optional filtering by instrument type.
Basic Usage
l, err := lookup.New("Apple")
if err != nil {
log.Fatal(err)
}
defer l.Close()
// Get all matching instruments
results, err := l.All(10)
if err != nil {
log.Fatal(err)
}
for _, doc := range results {
fmt.Printf("%s: %s (%s)\n", doc.Symbol, doc.Name, doc.QuoteType)
}
Filtering by Type
You can filter results by specific instrument types:
// Get only stocks
stocks, err := l.Stock(10)
// Get only ETFs
etfs, err := l.ETF(10)
// Get only mutual funds
funds, err := l.MutualFund(10)
// Get only indices
indices, err := l.Index(10)
// Get only futures
futures, err := l.Future(10)
// Get only currencies
currencies, err := l.Currency(10)
// Get only cryptocurrencies
cryptos, err := l.Cryptocurrency(10)
Pricing Data
By default, lookup results include real-time pricing data such as:
- RegularMarketPrice: Current market price
- RegularMarketChange: Price change
- RegularMarketChangePercent: Percentage change
- RegularMarketVolume: Trading volume
- MarketCap: Market capitalization
- FiftyTwoWeekHigh/Low: 52-week price range
Caching
Lookup results are cached per query/type combination. To clear the cache:
Custom Client
You can provide a custom HTTP client for the Lookup instance:
Thread Safety
All Lookup methods are safe for concurrent use from multiple goroutines.
Python Compatibility
This package implements the same functionality as Python yfinance's Lookup class:
Python | Go
----------------------------|---------------------------
yf.Lookup("AAPL") | lookup.New("AAPL")
lookup.get_all(count=10) | l.All(10)
lookup.get_stock(count=10) | l.Stock(10)
lookup.get_etf(count=10) | l.ETF(10)
lookup.get_mutualfund(10) | l.MutualFund(10)
lookup.get_index(count=10) | l.Index(10)
lookup.get_future(count=10) | l.Future(10)
lookup.get_currency(10) | l.Currency(10)
lookup.get_cryptocurrency() | l.Cryptocurrency(10)
Index
- type Lookup
- func New(query string, opts ...Option) (*Lookup, error)
- func (l *Lookup) All(count int) ([]models.LookupDocument, error)
- func (l *Lookup) ClearCache()
- func (l *Lookup) Close()
- func (l *Lookup) Cryptocurrency(count int) ([]models.LookupDocument, error)
- func (l *Lookup) Currency(count int) ([]models.LookupDocument, error)
- func (l *Lookup) ETF(count int) ([]models.LookupDocument, error)
- func (l *Lookup) Future(count int) ([]models.LookupDocument, error)
- func (l *Lookup) Index(count int) ([]models.LookupDocument, error)
- func (l *Lookup) MutualFund(count int) ([]models.LookupDocument, error)
- func (l *Lookup) Query() string
- func (l *Lookup) Stock(count int) ([]models.LookupDocument, error)
- type Option
- func WithClient(c *client.Client) Option
type Lookup
Lookup provides Yahoo Finance ticker lookup functionality.
Lookup allows searching for financial instruments by query string, with optional filtering by instrument type.
func New
New creates a new Lookup instance for the given query.
The query can be a ticker symbol, company name, or partial match.
Example:
l, err := lookup.New("AAPL")
if err != nil {
log.Fatal(err)
}
defer l.Close()
results, err := l.All(10)
for _, doc := range results {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) All
All returns all types of financial instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
results, err := l.All(10)
for _, doc := range results {
fmt.Printf("%s: %s (%s)\n", doc.Symbol, doc.Name, doc.QuoteType)
}
func (*Lookup) ClearCache
ClearCache clears the cached lookup results.
func (*Lookup) Close
Close releases resources used by the Lookup instance.
func (*Lookup) Cryptocurrency
Cryptocurrency returns cryptocurrency instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
cryptos, err := l.Cryptocurrency(10)
for _, doc := range cryptos {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) Currency
Currency returns currency instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
currencies, err := l.Currency(10)
for _, doc := range currencies {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) ETF
ETF returns ETF instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
func (*Lookup) Future
Future returns futures instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
futures, err := l.Future(10)
for _, doc := range futures {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) Index
Index returns index instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
indices, err := l.Index(10)
for _, doc := range indices {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) MutualFund
MutualFund returns mutual fund instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
funds, err := l.MutualFund(10)
for _, doc := range funds {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
func (*Lookup) Query
Query returns the search query string.
func (*Lookup) Stock
Stock returns equity/stock instruments matching the query.
Parameters:
- count: Maximum number of results to return (default 25 if \<= 0)
Example:
stocks, err := l.Stock(10)
for _, doc := range stocks {
fmt.Printf("%s: %s\n", doc.Symbol, doc.Name)
}
type Option
Option is a function that configures a Lookup instance.
func WithClient
WithClient sets a custom HTTP client for the Lookup instance.