Skip to content
⚠️ Deprecrated in favor of https://github.com/piquette/finance-go ⚠️
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/health Change history and events to use the new API. Jun 10, 2017
fixtures Reduce html fixture. Oct 12, 2017
.gitignore Change history and events to use the new API. Jun 10, 2017
.travis.yml Add new version to travis. Mar 2, 2017
LICENSE.md Change license, add fields to quote, handle multiple quotes error. Mar 2, 2017
README.md Deprecation announcement. Mar 9, 2018
datetime.go Change history and events to use the new API. Jun 10, 2017
datetime_test.go Change history and events to use the new API. Jun 10, 2017
doc.go Include some options tests. Apr 14, 2016
fetch.go Change history and events to use the new API. Jun 10, 2017
fetch_test.go Change history and events to use the new API. Jun 10, 2017
fields.go Change history and events to use the new API. Jun 10, 2017
history.go Merge pull request #10 from FlashBoys/GOFIN-2 Jun 13, 2017
history_test.go Change history and events to use the new API. Jun 10, 2017
option.go New datetime constructor, update readme. Mar 3, 2017
option_test.go Run gofmt s, add err checks. Mar 7, 2017
options.go Refactor options and merge time structs. Mar 2, 2017
options_test.go Run gofmt s, add err checks. Mar 7, 2017
pairs.go Change history and events to use the new API. Jun 10, 2017
pairs_test.go Add history and pairs tests. Mar 2, 2017
quotes.go Change history and events to use the new API. Jun 10, 2017
quotes_test.go Change history and events to use the new API. Jun 10, 2017
symbols.go Change history and events to use the new API. Jun 10, 2017
symbols_test.go Add tests for symbols and utils. Mar 2, 2017
utils.go Change history and events to use the new API. Jun 10, 2017
utils_test.go Change history and events to use the new API. Jun 10, 2017

README.md

go-finance

GoDoc Build Status codecov.io Go Report Card License MIT

codecov.io

go-finance is a Go library for retrieving financial data for quantitative analysis.

Deprecation Warning!

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

---Deprecated---

To install go-finance, use the following command:

go get github.com/FlashBoys/go-finance

Features

Single security quotes

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)
	}
}

Multiple securities quotes

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)
	}
}

Currency pair quote

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)
	}
}

Quote history

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)
	}
}

Dividend/Split event history

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)
	}
}

Symbols download

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)
	}
}

Options chains

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)
}

Intentions

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.

API Changes

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 or finance.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!

Contributing

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.

Similar Projects

You can’t perform that action at this time.