Documentation
¶
Index ¶
- Constants
- func CheckResponse(res *http.Response) error
- func DecodeResponse(target interface{}, res *http.Response) error
- func GetClient() *http.Client
- func JSONReader(v interface{}) (io.Reader, error)
- func ResolveRelative(basePath string, elem ...string) string
- func SendRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
- type Adjclose
- type BetweenCall
- type Chart
- type CurrentTradingPeriod
- type DefaultCall
- type Dividend
- type Error
- type ErrorHistory
- type Events
- type HistoryService
- type Indicators
- type Infomation
- type Meta
- type PeriodCall
- type Quote
- type QuoteService
- type RegularMarketPriceCall
- type Result
- type ServerResponse
- type Service
- type Split
- type TimeInfo
Examples ¶
Constants ¶
const (
HOST = "https://query1.finance.yahoo.com/"
)
const strings
Variables ¶
This section is empty.
Functions ¶
func CheckResponse ¶
CheckResponse returns an error (of type *Error) if the response status code is not 2xx.
func DecodeResponse ¶
DecodeResponse decodes the body of res into target. If there is no body, target is unchanged.
func JSONReader ¶
JSONReader convert struct to reader for json request
func ResolveRelative ¶
ResolveRelative join path
Types ¶
type BetweenCall ¶
type BetweenCall struct { DefaultCall // contains filtered or unexported fields }
BetweenCall call function
func (*BetweenCall) IncludeAdjustedClose ¶
func (c *BetweenCall) IncludeAdjustedClose(s string) *BetweenCall
IncludeAdjustedClose Adjust Close Default is true
func (*BetweenCall) Interval ¶
func (c *BetweenCall) Interval(s string) *BetweenCall
Interval Default is 1d Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo Intraday data cannot extend last 60 days
type Chart ¶
type Chart struct { Result []Result `json:"result"` Error ErrorHistory `json:"error"` }
Chart Chart
type CurrentTradingPeriod ¶
type CurrentTradingPeriod struct { Pre TimeInfo `json:"pre"` Regular TimeInfo `json:"regular"` Post TimeInfo `json:"post"` }
CurrentTradingPeriod CurrentTradingPeriod
type DefaultCall ¶
type DefaultCall struct {
// contains filtered or unexported fields
}
DefaultCall DefaultCall function
func (*DefaultCall) Context ¶
func (c *DefaultCall) Context(ctx context.Context) *DefaultCall
Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.
func (*DefaultCall) Header ¶
func (c *DefaultCall) Header() http.Header
Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.
type Error ¶
type Error struct { // Code is the HTTP response status code and will always be populated. Code int `json:"code,omitempty"` // Message is the server response message and is only populated when // explicitly referenced by the JSON server response. Message string `json:"message,omitempty"` // Body is the raw response returned by the server. // It is often but not always JSON, depending on how the request fails. Body string // Header contains the response header fields from the server. Header http.Header }
Error contains an error response from the server.
type ErrorHistory ¶
ErrorHistory ErrorHistory
type Events ¶
type Events struct { Dividends map[string]Dividend `json:"dividends"` Splits map[string]Split `json:"splits"` }
Events Events
type HistoryService ¶
type HistoryService struct {
// contains filtered or unexported fields
}
HistoryService get history
func NewHistoryService ¶
func NewHistoryService(s *Service) *HistoryService
NewHistoryService get history
func (*HistoryService) Between ¶
func (r *HistoryService) Between(symbol string, start, end time.Time) *BetweenCall
Between get data in period https://query1.finance.yahoo.com/v8/finance/chart/0050.TW?range=7d&interval=1d&includeAdjustedClose=true&events="div,splits" https://query1.finance.yahoo.com/v8/finance/chart/VTI?period1=-2208988800&period2=1607299200&interval=1d&includeAdjustedClose=true&events="div,splits"
:Parameters: period : str Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max Either Use period parameter or use start and end interval : str Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo Intraday data cannot extend last 60 days start: str Download start date string (YYYY-MM-DD) or _datetime. Default is 1900-01-01 end: str Download end date string (YYYY-MM-DD) or _datetime. Default is now
func (*HistoryService) Period ¶
func (r *HistoryService) Period(symbol, period, interval string) *PeriodCall
Period get data in period https://query1.finance.yahoo.com/v8/finance/chart/0050.TW?range=7d&interval=1d&includeAdjustedClose=true&events="div,splits" https://query1.finance.yahoo.com/v8/finance/chart/VTI?period1=-2208988800&period2=1607299200&interval=1d&includeAdjustedClose=true&events="div,splits"
:Parameters: period : str Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max Either Use period parameter or use start and end interval : str Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo Intraday data cannot extend last 60 days start: str Download start date string (YYYY-MM-DD) or _datetime. Default is 1900-01-01 end: str Download end date string (YYYY-MM-DD) or _datetime. Default is now
Example ¶
client := GetClient() yfinance, err := New(client) if err != nil { panic(err) } call := yfinance.History.Period("0050.TW", "1mo", "1d") history, err := call.Do() if err != nil { panic(err) } fmt.Printf("%+v", history)
Output:
type Indicators ¶
Indicators Indicators
type Infomation ¶
type Infomation struct { // ServerResponse contains the HTTP response code and headers from the // server. ServerResponse `json:"-"` Chart Chart `json:"chart"` }
Infomation Infomation
type Meta ¶
type Meta struct { Currency string `json:"currency"` Symbol string `json:"symbol"` ExchangeName string `json:"exchangeName"` InstrumentType string `json:"instrumentType"` FirstTradeDate int64 `json:"firstTradeDate"` RegularMarketTime int64 `json:"regularMarketTime"` Gmtoffset int64 `json:"gmtoffset"` Timezone string `json:"timezone"` ExchangeTimezoneName string `json:"exchangeTimezoneName"` RegularMarketPrice float64 `json:"regularMarketPrice"` ChartPreviousClose float64 `json:"chartPreviousClose"` PriceHint int `json:"priceHint"` CurrentTradingPeriod CurrentTradingPeriod `json:"currentTradingPeriod"` DataGranularity string `json:"dataGranularity"` Range string `json:"range"` ValidRanges []string `json:"validRanges"` }
Meta Meta
type PeriodCall ¶
type PeriodCall struct { DefaultCall // contains filtered or unexported fields }
PeriodCall call function
func (*PeriodCall) IncludeAdjustedClose ¶
func (c *PeriodCall) IncludeAdjustedClose(s string) *PeriodCall
IncludeAdjustedClose Adjust Close Default is true
type Quote ¶
type Quote struct { Volume []float64 `json:"volume"` Close []float64 `json:"close"` Open []float64 `json:"open"` High []float64 `json:"high"` Low []float64 `json:"low"` }
Quote Quote
type QuoteService ¶
type QuoteService struct {
// contains filtered or unexported fields
}
QuoteService get history
func (*QuoteService) RegularMarketPrice ¶
func (r *QuoteService) RegularMarketPrice(symbol string) *RegularMarketPriceCall
RegularMarketPrice get last price https://query1.finance.yahoo.com/v8/finance/chart/0050.TW?range=7d&interval=1d&includeAdjustedClose=true&events="div,splits" https://query1.finance.yahoo.com/v8/finance/chart/VTI?period1=-2208988800&period2=1607299200&interval=1d&includeAdjustedClose=true&events="div,splits"
:Parameters: period : str Valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max Either Use period parameter or use start and end interval : str Valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo Intraday data cannot extend last 60 days start: str Download start date string (YYYY-MM-DD) or _datetime. Default is 1900-01-01 end: str Download end date string (YYYY-MM-DD) or _datetime. Default is now
type RegularMarketPriceCall ¶
type RegularMarketPriceCall struct { DefaultCall // contains filtered or unexported fields }
RegularMarketPriceCall call function
func (*RegularMarketPriceCall) Do ¶
func (c *RegularMarketPriceCall) Do() (*Infomation, error)
Do send request
type Result ¶
type Result struct { Meta Meta `json:"meta"` Timestamp []int64 `json:"timestamp"` Events Events `json:"events"` Indicators Indicators `json:"indicators"` }
Result Result
type ServerResponse ¶
type ServerResponse struct { // HTTPStatusCode is the server's response status code. When using a // resource method's Do call, this will always be in the 2xx range. HTTPStatusCode int // Header contains the response header fields from the server. Header http.Header }
ServerResponse is embedded in each Do response and provides the HTTP status code and header sent by the server.
type Service ¶
type Service struct { History *HistoryService Quote *QuoteService // contains filtered or unexported fields }
Service Yahoo Finance api