Documentation
¶
Index ¶
- Variables
- type Client
- type History
- type HistoryQuery
- type Information
- type Option
- type OptionData
- type OptionDetail
- type PriceData
- type PriceValue
- type Search
- type SearchData
- type SearchParams
- type SearchResult
- type Ticker
- func (t *Ticker) ExpirationDates() []string
- func (t *Ticker) History(query HistoryQuery) (map[string]PriceData, error)
- func (t *Ticker) Info() (YahooTickerInfo, error)
- func (t *Ticker) OptionChain() OptionData
- func (t *Ticker) OptionChainByExpiration(expiration string) OptionData
- func (t *Ticker) Quote() (PriceData, error)
- func (t *Ticker) Search(query string, limit int) ([]SearchResult, error)
- func (t *Ticker) SearchWithOptions(params SearchParams) ([]SearchResult, error)
- type YahooChart
- type YahooHistoryRespose
- type YahooHistoryResult
- type YahooIndicator
- type YahooInfoResponse
- type YahooMeta
- type YahooOption
- type YahooOptionChain
- type YahooOptionQuote
- type YahooOptionResponse
- type YahooOptionResult
- type YahooOptions
- type YahooQuote
- type YahooSearchResponse
- type YahooTickerInfo
- type YahooTradingPeriod
Constants ¶
This section is empty.
Variables ¶
var BASE_URL = "https://query2.finance.yahoo.com"
var USER_AGENTS = []string{
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14.7; rv:135.0) Gecko/20100101 Firefox/135.0",
"Mozilla/5.0 (X11; Linux i686; rv:135.0) Gecko/20100101 Firefox/135.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/131.0.2903.86",
}
Functions ¶
This section is empty.
Types ¶
type History ¶
type History struct {
// contains filtered or unexported fields
}
func (*History) GetHistory ¶
func (h *History) GetHistory(symbol string) (YahooHistoryRespose, error)
returns the price/volume history of the given symbol as a YahooHistoryResponse If you want to adjust the query range change h.query.Range = "6mo" for 6 month
func (*History) SetQuery ¶
func (h *History) SetQuery(query HistoryQuery)
type HistoryQuery ¶
func (*HistoryQuery) SetDefault ¶
func (hq *HistoryQuery) SetDefault()
type Information ¶ added in v0.1.3
type Information struct {
// contains filtered or unexported fields
}
Information holds the HTTP client
func (*Information) GetInfo ¶ added in v0.1.3
func (i *Information) GetInfo(symbol string) (YahooTickerInfo, error)
GetInfo fetches metadata information for a given ticker
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
func (*Option) GetExpirationDates ¶
func (*Option) GetOptionChain ¶
func (o *Option) GetOptionChain(symbol string) YahooOptionResponse
func (*Option) GetOptionChainByExpiration ¶
func (o *Option) GetOptionChainByExpiration(symbol string, expirationDate string) YahooOptionResponse
type OptionData ¶
type OptionData struct {
ExpirationDate string `json:"expirationDate"`
HasMiniOptions bool `json:"hasMiniOptions"`
Calls []OptionDetail `json:"calls"`
Puts []OptionDetail `json:"puts"`
}
type OptionDetail ¶
type OptionDetail struct {
ContractSymbol string `json:"contractSymbol"`
Strike float64 `json:"strike"`
Currency string `json:"currency"`
LastPrice float64 `json:"lastPrice"`
Change float64 `json:"change"`
PercentChange float64 `json:"percentChange"`
Volume int64 `json:"volume"`
OpenInterest int64 `json:"openInterest"`
Bid float64 `json:"bid"`
Ask float64 `json:"ask"`
ContractSize string `json:"contractSize"`
Expiration string `json:"expiration"`
LastTradeDate string `json:"lastTradeDate"`
ImpliedVolatility float64 `json:"impliedVolatility"`
InTheMoney bool `json:"inTheMoney"`
}
type PriceValue ¶ added in v0.1.3
type PriceValue struct {
Raw float64 `json:"raw"`
Fmt string `json:"fmt"`
LongFmt string `json:"longFmt,omitempty"`
}
PriceValue represents a price value with raw and formatted representations
type Search ¶ added in v0.1.3
type Search struct {
// contains filtered or unexported fields
}
Search holds the HTTP client for symbol searching
func (*Search) GetSearchResults ¶ added in v0.1.3
func (s *Search) GetSearchResults(query string, limit int) (YahooSearchResponse, error)
GetSearchResults searches for investment symbols by query using Yahoo Finance's public search API API endpoint: https://query2.finance.yahoo.com/v1/finance/search
This is a convenience function that uses default search parameters. For custom parameters, use GetSearchResultsWithOptions.
Parameters:
- query: Search query (symbol, company name, etc.)
- limit: Maximum number of results to return (max 20)
Returns:
- YahooSearchResponse: Raw search response from Yahoo Finance
- error: Error if request fails or query is invalid
func (*Search) GetSearchResultsWithOptions ¶ added in v0.1.3
func (s *Search) GetSearchResultsWithOptions(params SearchParams) (YahooSearchResponse, error)
GetSearchResultsWithOptions searches for investment symbols using custom parameters
Parameters:
- params: SearchParams with custom configuration
Returns:
- YahooSearchResponse: Raw search response from Yahoo Finance
- error: Error if request fails or query is invalid
type SearchData ¶ added in v0.1.3
type SearchData struct {
Results []SearchResult
}
SearchData represents the transformed search results
type SearchParams ¶ added in v0.1.3
type SearchParams struct {
// Core search parameters
Query string // Search query (symbol, company name, etc.)
QuotesCount int // Number of quote results to return (default: 10, max: 20)
NewsCount int // Number of news results (default: 0, not needed for symbol search)
ListsCount int // Number of list results (default: 0, not needed)
// Query optimization parameters
EnableFuzzyQuery bool // Enable fuzzy matching (default: false for exact matching)
EnableEnhancedTrivialQuery bool // Enable better trivial query handling (default: true)
EnableCccBoost bool // Enable cryptocurrency boost (default: true)
EnablePrivateCompany bool // Include private companies (default: true)
// Feature flags
EnableResearchReports bool // Enable research reports data (default: true)
EnableCulturalAssets bool // Enable cultural assets data (default: true)
EnableLogoUrl bool // Enable logo URLs (default: true)
EnableCb bool // Enable clickback (default: false)
EnableLists bool // Enable lists in results (default: false)
// Query IDs (Yahoo Finance internal query routing)
QuotesQueryId string // Default: "tss_match_phrase_query"
MultiQuoteQueryId string // Default: "multi_quote_single_token_query"
NewsQueryId string // Default: "news_cie_vespa" (not used when newsCount=0)
// Recommendation
RecommendCount int // Number of recommendations (default: 5)
// Language
Lang string // Language code (default: "en-US")
}
SearchParams holds configurable parameters for Yahoo Finance search API
func DefaultSearchParams ¶ added in v0.1.3
func DefaultSearchParams(query string, quotesCount int) SearchParams
DefaultSearchParams returns the default search parameters optimized for symbol lookup
type SearchResult ¶ added in v0.1.3
type SearchResult struct {
Symbol string `json:"symbol"`
Name string `json:"name"`
ShortName string `json:"shortname"`
LongName string `json:"longname"`
Type string `json:"type"`
Exchange string `json:"exchange"`
ExchDisp string `json:"exchDisp"`
}
SearchResult represents a symbol search result from Yahoo Finance
type Ticker ¶
type Ticker struct {
Symbol string
// contains filtered or unexported fields
}
func NewTicker ¶
NewTicker creates a new Ticker instance for the given symbol. It initializes the history, option, and information components needed to fetch historical price data, options data, and ticker information.
func (*Ticker) ExpirationDates ¶
ExpirationDates retrieves a list of available expiration dates for options on the Ticker's symbol. It returns a slice of strings representing the expiration dates.
func (*Ticker) History ¶
func (t *Ticker) History(query HistoryQuery) (map[string]PriceData, error)
History retrieves the historical price data for the Ticker's symbol based on the provided query. It returns a map of date strings to PriceData structs. The query can specify the range, interval, and other parameters for the historical data.
func (*Ticker) Info ¶ added in v0.1.3
func (t *Ticker) Info() (YahooTickerInfo, error)
Info retrieves the ticker information for the Ticker's symbol. It returns a YahooTickerInfo struct containing metadata such as the symbol, name, currency, and market state. If no information is found, it returns an error.
func (*Ticker) OptionChain ¶
func (t *Ticker) OptionChain() OptionData
OptionChain retrieves the option chain for the Ticker's symbol. It returns an OptionData struct containing the options available for the ticker. If no options are found, it returns an empty OptionData struct.
func (*Ticker) OptionChainByExpiration ¶
func (t *Ticker) OptionChainByExpiration(expiration string) OptionData
OptionChainByExpiration retrieves the option chain for the Ticker's symbol filtered by a specific expiration date. It returns an OptionData struct containing the options available for the ticker on that expiration date. If no options are found for the specified expiration, it returns an empty OptionData struct.
func (*Ticker) Quote ¶ added in v0.1.2
Quote returns the latest PriceData for the Ticker's symbol. This is a convenience wrapper around the History function. It fetches the historical price data for the symbol, sorts the dates, and returns the most recent entry. If you need more control or access to the full historical data, use the History method directly.
func (*Ticker) Search ¶ added in v0.1.3
func (t *Ticker) Search(query string, limit int) ([]SearchResult, error)
Search searches for investment symbols by query using Yahoo Finance's public search API. This is a convenience function that uses default search parameters.
Parameters:
- query: Search query (symbol, company name, etc.)
- limit: Maximum number of results to return (max 20, default 10)
Returns:
- []SearchResult: List of search results
- error: Error if request fails or query is invalid
func (*Ticker) SearchWithOptions ¶ added in v0.1.3
func (t *Ticker) SearchWithOptions(params SearchParams) ([]SearchResult, error)
SearchWithOptions searches for investment symbols using custom parameters.
Parameters:
- params: SearchParams with custom configuration
Returns:
- []SearchResult: List of search results
- error: Error if request fails or query is invalid
type YahooChart ¶
type YahooChart struct {
Result []YahooHistoryResult `json:"result"`
}
type YahooHistoryRespose ¶
type YahooHistoryRespose struct {
Chart YahooChart `json:"chart"`
}
type YahooHistoryResult ¶
type YahooHistoryResult struct {
Meta YahooMeta `json:"meta"`
Timestamp []int64 `json:"timestamp"`
Indicators YahooIndicator `json:"indicators"`
}
type YahooIndicator ¶
type YahooIndicator struct {
Quote []YahooQuote `json:"quote"`
}
type YahooInfoResponse ¶ added in v0.1.3
type YahooInfoResponse struct {
QuoteSummary struct {
Result []struct {
Price YahooTickerInfo `json:"price"`
} `json:"result"`
Error interface{} `json:"error"`
} `json:"quoteSummary"`
}
YahooInfoResponse --> Struct to hold the result from the Yahoo Finance quoteSummary endpoint
type YahooMeta ¶
type YahooMeta struct {
Currency string `json:"currency"`
Symbol string `json:"symbol"`
ExchangeName string `json:"exchangeName"`
FullExchangeName string `json:"fullExchangeName"`
InstrumentType string `json:"instrumentType"`
FirstTradeDate int64 `json:"firstTradeDate"`
RegularMarketTime int64 `json:"regularMarketTime"`
HasPrePostMarketData bool `json:"hasPrePostMarketData"`
GmtOffset int `json:"gmtoffset"`
Timezone string `json:"timezone"`
ExchangeTimezoneName string `json:"exchangeTimezoneName"`
RegularMarketPrice float64 `json:"regularMarketPrice"`
FiftyTwoWeekHigh float64 `json:"fiftyTwoWeekHigh"`
FiftyTwoWeekLow float64 `json:"fiftyTwoWeekLow"`
RegularMarketDayHigh float64 `json:"regularMarketDayHigh"`
RegularMarketDayLow float64 `json:"regularMarketDayLow"`
RegularMarketVolume int64 `json:"regularMarketVolume"`
LongName string `json:"longName"`
ShortName string `json:"shortName"`
ChartPreviousClose float64 `json:"chartPreviousClose"`
PreviousClose float64 `json:"previousClose"`
Scale int `json:"scale"`
PriceHint int `json:"priceHint"`
CurrentTradingPeriod YahooTradingPeriod `json:"currentTradingPeriod"`
TradingPeriods [][]YahooTradingPeriod `json:"tradingPeriods"`
DataGranularity string `json:"dataGranularity"`
Range string `json:"range"`
ValidRanges []string `json:"validRanges"`
}
type YahooOption ¶
type YahooOption struct {
ContractSymbol string `json:"contractSymbol"`
Strike float64 `json:"strike"`
Currency string `json:"currency"`
LastPrice float64 `json:"lastPrice"`
Change float64 `json:"change"`
PercentChange float64 `json:"percentChange"`
Volume int64 `json:"volume"`
OpenInterest int64 `json:"openInterest"`
Bid float64 `json:"bid"`
Ask float64 `json:"ask"`
ContractSize string `json:"contractSize"`
Expiration int64 `json:"expiration"`
LastTradeDate int64 `json:"lastTradeDate"`
ImpliedVolatility float64 `json:"impliedVolatility"`
InTheMoney bool `json:"inTheMoney"`
}
type YahooOptionChain ¶
type YahooOptionChain struct {
Result []YahooOptionResult `json:"result"`
Error any `json:"error"`
}
type YahooOptionQuote ¶
type YahooOptionQuote struct {
Language string `json:"language"`
Region string `json:"region"`
QuoteType string `json:"quoteType"`
TypeDisp string `json:"typeDisp"`
QuoteSourceName string `json:"quoteSourceName"`
Triggerable bool `json:"triggerable"`
CustomPriceAlertConfidence string `json:"customPriceAlertConfidence"`
MarketState string `json:"marketState"`
RegularMarketChangePercent float64 `json:"regularMarketChangePercent"`
RegularMarketPrice float64 `json:"regularMarketPrice"`
ShortName string `json:"shortName"`
LongName string `json:"longName"`
Exchange string `json:"exchange"`
MessageBoardId string `json:"messageBoardId"`
ExchangeTimezoneName string `json:"exchangeTimezoneName"`
ExchangeTimezoneShortName string `json:"exchangeTimezoneShortName"`
GmtOffSetMilliseconds int64 `json:"gmtOffSetMilliseconds"`
Market string `json:"market"`
EsgPopulated bool `json:"esgPopulated"`
Currency string `json:"currency"`
HasPrePostMarketData bool `json:"hasPrePostMarketData"`
FirstTradeDateMilliseconds int64 `json:"firstTradeDateMilliseconds"`
PriceHint int `json:"priceHint"`
PostMarketChangePercent float64 `json:"postMarketChangePercent"`
PostMarketPrice float64 `json:"postMarketPrice"`
PostMarketChange float64 `json:"postMarketChange"`
RegularMarketChange float64 `json:"regularMarketChange"`
RegularMarketDayHigh float64 `json:"regularMarketDayHigh"`
RegularMarketDayRange string `json:"regularMarketDayRange"`
RegularMarketDayLow float64 `json:"regularMarketDayLow"`
RegularMarketVolume int64 `json:"regularMarketVolume"`
RegularMarketPreviousClose float64 `json:"regularMarketPreviousClose"`
Bid float64 `json:"bid"`
Ask float64 `json:"ask"`
BidSize int `json:"bidSize"`
AskSize int `json:"askSize"`
FullExchangeName string `json:"fullExchangeName"`
FinancialCurrency string `json:"financialCurrency"`
RegularMarketOpen float64 `json:"regularMarketOpen"`
AverageDailyVolume3Month int64 `json:"averageDailyVolume3Month"`
AverageDailyVolume10Day int64 `json:"averageDailyVolume10Day"`
FiftyTwoWeekLowChange float64 `json:"fiftyTwoWeekLowChange"`
FiftyTwoWeekLowChangePercent float64 `json:"fiftyTwoWeekLowChangePercent"`
FiftyTwoWeekRange string `json:"fiftyTwoWeekRange"`
FiftyTwoWeekHighChange float64 `json:"fiftyTwoWeekHighChange"`
FiftyTwoWeekHighChangePercent float64 `json:"fiftyTwoWeekHighChangePercent"`
FiftyTwoWeekLow float64 `json:"fiftyTwoWeekLow"`
FiftyTwoWeekHigh float64 `json:"fiftyTwoWeekHigh"`
FiftyTwoWeekChangePercent float64 `json:"fiftyTwoWeekChangePercent"`
DividendDate int64 `json:"dividendDate"`
EarningsTimestamp int64 `json:"earningsTimestamp"`
EarningsTimestampStart int64 `json:"earningsTimestampStart"`
EarningsTimestampEnd int64 `json:"earningsTimestampEnd"`
EarningsCallTimestampStart int64 `json:"earningsCallTimestampStart"`
EarningsCallTimestampEnd int64 `json:"earningsCallTimestampEnd"`
IsEarningsDateEstimate bool `json:"isEarningsDateEstimate"`
TrailingAnnualDividendRate float64 `json:"trailingAnnualDividendRate"`
TrailingPE float64 `json:"trailingPE"`
DividendRate float64 `json:"dividendRate"`
TrailingAnnualDividendYield float64 `json:"trailingAnnualDividendYield"`
DividendYield float64 `json:"dividendYield"`
EpsTrailingTwelveMonths float64 `json:"epsTrailingTwelveMonths"`
EpsForward float64 `json:"epsForward"`
EpsCurrentYear float64 `json:"epsCurrentYear"`
PriceEpsCurrentYear float64 `json:"priceEpsCurrentYear"`
BookValue float64 `json:"bookValue"`
FiftyDayAverage float64 `json:"fiftyDayAverage"`
FiftyDayAverageChange float64 `json:"fiftyDayAverageChange"`
FiftyDayAverageChangePercent float64 `json:"fiftyDayAverageChangePercent"`
TwoHundredDayAverage float64 `json:"twoHundredDayAverage"`
TwoHundredDayAverageChange float64 `json:"twoHundredDayAverageChange"`
TwoHundredDayAverageChangePercent float64 `json:"twoHundredDayAverageChangePercent"`
MarketCap int64 `json:"marketCap"`
ForwardPE float64 `json:"forwardPE"`
PriceToBook float64 `json:"priceToBook"`
SourceInterval int `json:"sourceInterval"`
ExchangeDataDelayedBy int `json:"exchangeDataDelayedBy"`
AverageAnalystRating string `json:"averageAnalystRating"`
Tradeable bool `json:"tradeable"`
CryptoTradeable bool `json:"cryptoTradeable"`
CorporateActions []any `json:"corporateActions"`
PostMarketTime int64 `json:"postMarketTime"`
RegularMarketTime int64 `json:"regularMarketTime"`
DisplayName string `json:"displayName"`
Symbol string `json:"symbol"`
}
type YahooOptionResponse ¶
type YahooOptionResponse struct {
OptionChain YahooOptionChain `json:"optionChain"`
}
type YahooOptionResult ¶
type YahooOptionResult struct {
UnderlyingSymbol string `json:"underlyingSymbol"`
ExpirationDates []int64 `json:"expirationDates"`
Strikes []float64 `json:"strikes"`
HasMiniOptions bool `json:"hasMiniOptions"`
Quote YahooOptionQuote `json:"quote"`
Options []YahooOptions `json:"options"`
}
type YahooOptions ¶
type YahooOptions struct {
ExpirationDate int64 `json:"expirationDate"`
HasMiniOptions bool `json:"hasMiniOptions"`
Calls []YahooOption `json:"calls"`
Puts []YahooOption `json:"puts"`
}
type YahooQuote ¶
type YahooSearchResponse ¶ added in v0.1.3
type YahooSearchResponse struct {
Quotes []struct {
Symbol string `json:"symbol"`
ShortName string `json:"shortname"`
LongName string `json:"longname"`
QuoteType string `json:"quoteType"`
Exchange string `json:"exchange"`
ExchDisp string `json:"exchDisp"`
TypeDisp string `json:"typeDisp"`
} `json:"quotes"`
News []any `json:"news"`
Lists []any `json:"lists"`
Research struct {
Reports []any `json:"reports"`
} `json:"reports"`
}
YahooSearchResponse represents the raw Yahoo Finance search API response
type YahooTickerInfo ¶ added in v0.1.3
type YahooTickerInfo struct {
MaxAge int `json:"maxAge"`
PreMarketChange *PriceValue `json:"preMarketChange"`
PreMarketPrice *PriceValue `json:"preMarketPrice"`
PreMarketSource string `json:"preMarketSource"`
PostMarketChangePercent *PriceValue `json:"postMarketChangePercent"`
PostMarketChange *PriceValue `json:"postMarketChange"`
PostMarketTime int64 `json:"postMarketTime"`
PostMarketPrice *PriceValue `json:"postMarketPrice"`
PostMarketSource string `json:"postMarketSource"`
RegularMarketChangePercent *PriceValue `json:"regularMarketChangePercent"`
RegularMarketChange *PriceValue `json:"regularMarketChange"`
RegularMarketTime int64 `json:"regularMarketTime"`
PriceHint *PriceValue `json:"priceHint"`
RegularMarketPrice *PriceValue `json:"regularMarketPrice"`
RegularMarketDayHigh *PriceValue `json:"regularMarketDayHigh"`
RegularMarketDayLow *PriceValue `json:"regularMarketDayLow"`
RegularMarketVolume *PriceValue `json:"regularMarketVolume"`
AverageDailyVolume10Day *PriceValue `json:"averageDailyVolume10Day"`
AverageDailyVolume3Month *PriceValue `json:"averageDailyVolume3Month"`
RegularMarketPreviousClose *PriceValue `json:"regularMarketPreviousClose"`
RegularMarketSource string `json:"regularMarketSource"`
RegularMarketOpen *PriceValue `json:"regularMarketOpen"`
StrikePrice *PriceValue `json:"strikePrice"`
OpenInterest *PriceValue `json:"openInterest"`
Exchange string `json:"exchange"`
ExchangeName string `json:"exchangeName"`
ExchangeDataDelayedBy int `json:"exchangeDataDelayedBy"`
MarketState string `json:"marketState"`
QuoteType string `json:"quoteType"`
Symbol string `json:"symbol"`
UnderlyingSymbol *string `json:"underlyingSymbol"`
ShortName string `json:"shortName"`
LongName string `json:"longName"`
Currency string `json:"currency"`
QuoteSourceName string `json:"quoteSourceName"`
CurrencySymbol string `json:"currencySymbol"`
FromCurrency *string `json:"fromCurrency"`
ToCurrency *string `json:"toCurrency"`
LastMarket *string `json:"lastMarket"`
Volume24Hr *PriceValue `json:"volume24Hr"`
VolumeAllCurrencies *PriceValue `json:"volumeAllCurrencies"`
CirculatingSupply *PriceValue `json:"circulatingSupply"`
MarketCap *PriceValue `json:"marketCap"`
}
YahooTickerInfo --> Struct to hold key metadata about the ticker