:warning: Deprecrated in favor of https://github.com/piquette/finance-go
go-finance
is a Go library for retrieving financial data for quantitative analysis.
This library will no longer be maintained due to several breaking yahoo finance api changes (surprise). The next gen iteration of this library that uses the newer apis (as well as a few other api integrations) will exist here - https://github.com/piquette/finance-go and is currently in early stages of development. Have an idea or want to get involved? @ me on twitter, @michael_ack. In the meantime, browse some memes - https://reddit.com/r/memes
To install go-finance, use the following command:
go get github.com/FlashBoys/go-finance
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// 15-min delayed full quote for Apple.
q, err := finance.GetQuote("AAPL")
if err == nil {
fmt.Println(q)
}
}
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// 15-min delayed full quotes for Apple, Twitter, and Facebook.
symbols := []string{"AAPL", "TWTR", "FB"}
quotes, err := finance.GetQuotes(symbols)
if err == nil {
fmt.Println(quotes)
}
}
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// Predefined pair constants
// e.g
//
// USDJPY
// EURUSD
// NZDUSD
//
pairquote, err := finance.GetCurrencyPairQuote(finance.USDJPY)
if err == nil {
fmt.Println(pairquote)
}
}
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// Set time frame to 1 month starting Jan. 1.
start := finance.ParseDatetime("1/1/2017")
end := finance.ParseDatetime("2/1/2017")
// Request daily history for TWTR.
// IntervalDaily OR IntervalWeekly OR IntervalMonthly are supported.
bars, err := finance.GetHistory("TWTR", start, end, finance.Day)
if err == nil {
fmt.Println(bars)
}
}
package main
import (
"fmt"
"time"
"github.com/FlashBoys/go-finance"
)
func main() {
// Set time range from Jan 2010 up to the current date.
// This example will return a slice of either dividends or splits.
start := finance.ParseDatetime("1/1/2010")
end := finance.NewDatetime(time.Now())
// Request event history for AAPL.
events, err := finance.GetEventHistory("AAPL", start, end, finance.Dividends)
if err == nil {
fmt.Println(events)
}
}
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// Request all BATS symbols.
symbols, err := finance.GetUSEquitySymbols()
if err == nil {
fmt.Println(symbols)
}
}
package main
import (
"fmt"
"github.com/FlashBoys/go-finance"
)
func main() {
// Fetches the available expiration dates.
c, err := finance.NewCycle("AAPL")
if err != nil {
panic(err)
}
// Some examples - see docs for full details.
// Fetches the chain for the front month.
calls, puts, err := c.GetFrontMonth()
if err == nil {
panic(err)
}
fmt.Println(calls)
fmt.Println(puts)
// Fetches the chain for the specified expiration date.
calls, puts, err := c.GetChainForExpiration(chain.Expirations[1])
if err == nil {
panic(err)
}
fmt.Println(calls)
fmt.Println(puts)
// Fetches calls for the specified expiration date.
calls, err := c.GetCallsForExpiration(chain.Expirations[1])
if err == nil {
panic(err)
}
fmt.Println(calls)
}
The primary technical tenants of this project are:
There are several applications for this library. It's intentions are to be conducive to the following activities:
Yahoo decided to deprecate the ichart API for historical data. A few things to note:
finance.Dividends
or finance.Splits
.You can use the new health checking command to determine if all the endpoints are responding appropriately. Run go run main.go
in the cmd/health
directory and report any failures!
If you find this repo helpful, please give it a star! If you wish to discuss changes to it, please open an issue. This project is not as mature as it could be, and financial projects in Go are in drastic need of some basic helpful dependencies.