:warning: Deprecrated in favor of https://github.com/piquette/finance-go

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

Owner
Deprecated. Please see-
null
Comments
  • Rename interval constants

    Rename interval constants

    Renamed the interval constants to match the README: finance.Day => finance.IntervalDaily finance.Week => finance.IntervalWeekly finance.Month => finance.IntervalMonthly

  • Fix the month encoding for yahoo history and event url construction.

    Fix the month encoding for yahoo history and event url construction.

    Yahoo are a bit wahoo and encode their months starting with Jan = 0.

    See https://github.com/pydata/pandas-datareader:

    pandas_datareader/yahoo/daily.py
    pandas_datareader/yahoo/actions.py
    
  • go-finance v2

    go-finance v2

    Total rewrite that aims to simplify naming conventions and model serialization while improving testability. Only truly breaking change is in the options section of the lib, see README for new syntax.

  • 'index out of range' for basic GetQuote example

    'index out of range' for basic GetQuote example

    main.go:

    package main
    
    import (
        "fmt"
    
        finance "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)
        }
    }
    
    $ go run main.go
    panic: runtime error: index out of range
    
    goroutine 1 [running]:
    github.com/FlashBoys/go-finance.mapFields(0xc42015a120, 0x3, 0x3, 0x29, 0x122b0c0, 0xc420035c00)
    	/go/src/github.com/FlashBoys/go-finance/fields.go:28 +0x737
    github.com/FlashBoys/go-finance.GetQuote(0x1294dfd, 0x4, 0x50, 0xc42007cc60, 0xc42008c8c0, 0x8, 0xc4200532f0, 0x11f3298, 0x126f5c0, 0xc420086230, ...)
    	/go/src/github.com/FlashBoys/go-finance/quotes.go:72 +0x2b3
    main.main()
    	/test.go:11 +0x75
    exit status 2
    
  • Verify If start date is before end date

    Verify If start date is before end date

    Hello,

    Not sure if this should be checked here or not.

    But if you try to GetHistory with end date before start date, you end up with some error like this:

    line 1, column 1: bare " in non-quoted-field
    

    Maybe this is when parsing the response from external api?

    Thanks

  • Causing

    Causing "index out of range" while the option has no entry on Expirations

    https://github.com/FlashBoys/go-finance/blob/65cfa107c234f30dfb4827807c798cca12d66c6f/options.go#L31

    package main
    
    import (
    	"fmt"
    	"github.com/FlashBoys/go-finance"
    )
    
    func main() {
    	c, err := finance.NewCycle("APPL") // Yes! Not "AAPL". "APPL" will fail.
    	if err != nil {
    		panic(err)
    	}
    
    	calls, puts, err := c.GetFrontMonth()
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(calls)
    	fmt.Println(puts)
    }
    
Go-Yahoo-Finance-Daily-Actives - Scrape for the daily actives on yh Finance and save the data to a CSV, and optionally send it to yourself as an email
Go-Yahoo-Finance-Daily-Actives - Scrape for the daily actives on yh Finance and save the data to a CSV, and optionally send it to yourself as an email

Go-Yahoo-Finance-Daily-Actives - Scrape for the daily actives on yh Finance and save the data to a CSV, and optionally send it to yourself as an email

Dec 13, 2022
Distributed lock manager. Warning: very hard to use it properly. Not because it's broken, but because distributed systems are hard. If in doubt, do not use this.

What Dlock is a distributed lock manager [1]. It is designed after flock utility but for multiple machines. When client disconnects, all his locks are

Dec 24, 2019
A shell for ignoring Android linker warning on termux

A shell for ignoring Android linker warning on termux!

Nov 10, 2021
*DEPRECATED* Please use https://gopkg.in/redsync.v1 (https://github.com/go-redsync/redsync)

Redsync.go This package is being replaced with https://gopkg.in/redsync.v1. I will continue to maintain this package for a while so that its users do

Nov 20, 2022
Rainbow is a dashboard for Decentralized Finance(DeFi) Options trading.
Rainbow is a dashboard for Decentralized Finance(DeFi) Options trading.

Rainbow is a dashboard for Decentralized Finance options trading. It's developed during Solana's Ignition & Ethereum's EthGlobal Hackathons by members

Dec 14, 2022
Renloi: a decentralized finance network for golang

Intro to Renloi A digital decentralized version of cash will allow extremely fas

Jun 9, 2022
Go-finproto - a collection of finance-related protocols implemented in Golang

go-finproto go-finproto is a collection of finance-related protocols implemented

Dec 25, 2022
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022
Go-github-actions - `go-github-actions` is a package for developing GitHub Actions

go-github-actions go-github-actions is a package for developing GitHub Actions.

Feb 6, 2022
Decode mp3 base on https://github.com/lieff/minimp3

minimp3 Decode mp3 base on https://github.com/lieff/minimp3 See examples in example directory. make and make test test the example. package main impo

Dec 25, 2022
go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config

HOCON (Human-Optimized Config Object Notation) Configuration library for working with the Lightbend's HOCON format. HOCON is a human-friendly JSON sup

Dec 3, 2022
A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist
A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist

Fast Skiplist Implementation This Go-library implements a very fast and efficient Skiplist that can be used as direct substitute for a balanced tree o

Dec 30, 2022
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron
:exclamation::exclamation::exclamation: [deprecated] Moved to https://github.com/go-macaron/macaron

Macaron Package macaron is a high productive and modular web framework in Go. Current version: 0.6.8 Getting Started The minimum requirement of Go is

Aug 20, 2021
Openldap (LDAP) binding for Golang (go) ; no more support ; you may have a look at https://github.com/go-ldap/ldap

OpenLDAP this is Openldap binding in GO language. I don't work any more with golang, so, please fork this project. Installation : Installation is easy

Mar 4, 2021
An Etsy StatsD (https://github.com/etsy/statsd) implementation in Go

STATSD-GO Port of Etsy's statsd, written in Go. This was forked from https://github.com/amir/gographite to provide Ganglia submission support. USAGE U

Mar 5, 2021
tiny linear interpolation library for go (factored out from https://github.com/sgreben/yeetgif)

piecewiselinear A tiny library for linear interpolation. O(log(N)) per evaluation for N control points. import "github.com/sgreben/piecewiselinear" Ge

Sep 27, 2022
auto-generate capnproto schema from your golang source files. Depends on go-capnproto-1.0 at https://github.com/glycerine/go-capnproto

bambam: auto-generate capnproto schema from your golang source files. Adding capnproto serialization to an existing Go project used to mean writing a

Sep 27, 2022
Cap'n Proto library and parser for go. This is go-capnproto-1.0, and does not have rpc. See https://github.com/zombiezen/go-capnproto2 for 2.0 which has rpc and capabilities.

Version 1.0 vs 2.0 Update 2015 Sept 20: Big news! Version 2.0 of the go-bindings, authored by Ross Light, is now released and newly available! It feat

Nov 29, 2022