Yahoo finance API wrapper for Go
import (
"github.com/bhoeting/go-yql-finance"
)
GetHistoricalData()
returns a slice of type HistoricalPiece
which is defined below:
type HistoricalPiece struct {
Low float64
High float64
Open float64
Close float64
Volume float64
AdjClose float64
Date time.Time
}
The function can be used like this:
// The second parameter is the time interval.
// You can pass in "d", "w", "m", "daily", "weekly", or "montly".
days := yql.GetHistoricalData("GOOG", "daily")
for _, day := range days {
fmt.Println(day.Close)
}
GetCurrentData()
returns a slice of type CurrentPiece
which is defined below:
type CurrentPiece struct {
Ask float64
Open float64
Name string
Symbol string
Change float64
PrevClose float64
}
The function can be used like this:
current := yql.GetCurrentData("GOOG", "AAPL")
for _, day := range days {
fmt.Println(day.Ask)
}
Both the CurrentPiece
and HistoricalPeice
types implement the interface TradingDay
type TradingDay interface {
Price() float64
}
Price()
returns the Ask
field from the CurrentPiece
and the Close
field from the HistoricalPiece