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:
- Make financial data easy and fun to work with in Go.
- Abstract the burden of non-sexy model serialization away from the end-user.
- Provide a mature framework where the end-user needs only be concerned with analysis instead of data sourcing.
There are several applications for this library. It's intentions are to be conducive to the following activities:
- Quantitative financial analysis in Go.
- Academic study/comparison in a clean, easy language.
- Algorithmic/Statistical-based strategy implementation.
Yahoo decided to deprecate the ichart API for historical data. A few things to note:
- Dividends and Splits got separated into their own calls, use
finance.Dividends
orfinance.Splits
. - A cookie and a crumb are now needed in the new historical API. This requires 2 calls, slowing down the response time/quality.
- Continuation of the historical data funcs were made possible by the solution proposed by pandas contributors here, so thanks for the help!
- That PR is also reporting a degradation of data quality in the responses, so watch out for that.
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.
- pandas datareader (Python) wide-spread use in academia.
- yahoofinance-api (Java) most popular java library for this purpose.
- quantmod (R) a package for development/testing/deployment of quant strategy.