finance

package module
v0.0.0-...-140800e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2017 License: Apache-2.0 Imports: 7 Imported by: 3

README

YFinance

Build Status GoDoc codecov Go Report Card License

YFinance is a golang library to retrieve financial data from yahoo yql finance table

To install yfinance, use the following command :

go get github.com/clebi/yfinance

Documentation

Index

Constants

View Source
const (

	// DateFormat for yahoo finance api
	DateFormat = "2006-01-02"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type History

type History struct {
	IYApi
	// contains filtered or unexported fields
}

History is the object to manage history api

func (*History) GetHistory

func (history *History) GetHistory(symbol string, start time.Time, end time.Time) ([]Stock, error)

GetHistory can be used to get the history values of a finance stock

history.GetHistory("GOOG", startDate, endDate)

Returns an array with the stock values for the corresponding period

type HistoryAPI

type HistoryAPI interface {
	GetHistory(symbol string, start time.Time, end time.Time) ([]Stock, error)
}

HistoryAPI allows to retrieve stocks history

func NewHistory

func NewHistory() HistoryAPI

NewHistory creates a new History api object

Return the new history api object

func NewHistoryTest

func NewHistoryTest(mockHistory IYApi) HistoryAPI

NewHistoryTest create an new history api object for test

Returns the new history api test object

type HistoryQuery

type HistoryQuery struct {
	Count   int            `json:"count"`
	Results HistoryResults `json:"results"`
}

HistoryQuery contains the data of an history query

type HistoryResponse

type HistoryResponse struct {
	Query HistoryQuery `json:"query"`
}

HistoryResponse is the response of the history query

type HistoryResults

type HistoryResults struct {
	Stocks []Stock `json:"quote"`
}

HistoryResults represents the results of an history query

type IYApi

type IYApi interface {
	Query(query string, responseObject interface{}) error
}

IYApi is the interface for the yahoo api

type Quote

type Quote struct {
	Symbol                     string  `json:"symbol"`
	Name                       string  `json:"Name"`
	LastTradePriceOnly         float32 `json:"LastTradePriceOnly,string"`
	FiftydayMovingAverage      float32 `json:"FiftydayMovingAverage,string"`
	TwoHundreddayMovingAverage float32 `json:"TwoHundreddayMovingAverage,string"`
	Volume                     int32   `json:"Volume,string"`
}

Quote represents a quote on yahoo api

type Quotes

type Quotes struct {
	IYApi
	// contains filtered or unexported fields
}

Quotes allows user to access yahoo finance quotes api

func (*Quotes) GetQuote

func (quotes *Quotes) GetQuote(symbol string) (*Quote, error)

GetQuote retrieves the quote values from yahoo yql

GetQuote("CW8.PA")

Returns the quote values

type QuotesAPI

type QuotesAPI interface {
	GetQuote(symbol string) (*Quote, error)
}

QuotesAPI allows user to Access yahoo finance quotes api

func NewQuotes

func NewQuotes() QuotesAPI

NewQuotes creates a new Quotes api object

Return the new quotes api object

type QuotesQuery

type QuotesQuery struct {
	Count   int           `json:"count"`
	Results QuotesResults `json:"results"`
}

QuotesQuery contains the data of a quotes query

type QuotesResponse

type QuotesResponse struct {
	Query QuotesQuery `json:"query"`
}

QuotesResponse is the response of the quotes query

type QuotesResults

type QuotesResults struct {
	Quote Quote `json:"quote"`
}

QuotesResults represents the results of an history query

type Stock

type Stock struct {
	Date   YTime   `json:"Date,string"`
	Open   float32 `json:"Open,string"`
	High   float32 `json:"High,string"`
	Low    float32 `json:"Low,string"`
	Close  float32 `json:"Close,string"`
	Volume int     `json:"Volume,string"`
	Symbol string  `json:"Symbol"`
}

Stock is an object containing stock values

type YApi

type YApi struct {
	// contains filtered or unexported fields
}

YApi is the yahoo finance api

func NewYApi

func NewYApi() *YApi

NewYApi create a new yahoo finance api object

Returns the new api object

func NewYApiTest

func NewYApiTest(URL string) *YApi

NewYApiTest create a new yahoo finance api test object

Returns the new api object

func (*YApi) Query

func (api *YApi) Query(query string, responseObject interface{}) error

Query execute a query on yahoo finance api responseObject will be used to store the api response

api.Query("select * from table where startDate = \"2016-01-01\"", responseObject)

Returns an error if something went wrong

type YApiError

type YApiError struct {
	Content YApiErrorContent `json:"error"`
}

YApiError represents a yahoo api error

func (YApiError) Error

func (err YApiError) Error() string

type YApiErrorContent

type YApiErrorContent struct {
	Lang        string `json:"lang"`
	Description string `json:"description"`
}

YApiErrorContent represents the content a yahoo api error

type YTime

type YTime struct {
	time.Time
}

YTime represents a date in yahoo finance api

func (*YTime) MarshalJSON

func (t *YTime) MarshalJSON() ([]byte, error)

MarshalJSON encode a date from yahoo api

func (*YTime) UnmarshalJSON

func (t *YTime) UnmarshalJSON(b []byte) error

UnmarshalJSON decode a date from yahoo api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL