📊 Financial markets data library implemented in go. https://piquette.io/projects/finance-go
  • Go 99.2%
  • Makefile 0.5%
  • Shell 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2023-08-06 22:39:03 -05:00
chart Fixes chart interface panic. 2018-08-30 00:21:57 -04:00
crypto Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
datetime Refactors datetime struct into its own package. 2018-07-08 15:28:44 -04:00
equity Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
etf Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
examples Fix lint and vet comments 2023-06-29 16:05:17 -04:00
forex Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
form Fix lint and vet comments 2023-06-29 16:05:17 -04:00
future Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
index Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
iter Refactors iter struct into its own package. 2018-07-08 16:46:15 -04:00
mutualfund Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
option Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
options Fix fetching data from Yahoo! finance 2023-06-29 11:05:52 -04:00
quote Fix broken test 2023-06-29 11:06:58 -04:00
scripts Adds Go modules support. 2019-09-22 16:03:59 -04:00
symbols Updates README to reflect current goals. 2018-05-11 00:08:46 -04:00
testing Adds Go modules support. 2019-09-22 16:03:59 -04:00
.gitignore Initial commit. 2018-05-10 22:21:14 -04:00
.travis.yml Adds Go modules support. 2019-09-22 16:03:59 -04:00
CHANGELOG.md Finalizes initial version. 2018-09-01 15:53:18 -04:00
error.go Add historical data. 2018-06-05 23:09:36 -04:00
finance.go Better handling of cookie expiry. 2023-07-01 16:31:35 -04:00
go.mod go mod tidy 2023-06-29 16:48:34 -04:00
go.sum Adds Go modules support. 2019-09-22 16:03:59 -04:00
LICENSE Initial commit. 2018-05-10 22:21:14 -04:00
Makefile Adds Go modules support. 2019-09-22 16:03:59 -04:00
README.md Adds Go modules support. 2019-09-22 16:03:59 -04:00
VERSION Finalizes initial version. 2018-09-01 15:53:18 -04:00
yfin.go added csv tags to structs 2021-04-28 23:27:48 -04:00

finance-go

GoDoc Build Status Coverage Status

Summary

This go package aims to provide a go application with access to current and historical financial markets data in streamlined, well-formatted structures.

Check out the qtrn cli application, which is intended as a living example of this package. It prints quotes/options info in your favorite command-line in a few keystrokes!

Features

Description Source
Quote(s) Yahoo finance
Equity quote(s) Yahoo finance
Index quote(s) Yahoo finance
Option quote(s) Yahoo finance
Forex pair quote(s) Yahoo finance
Cryptocurrency pair quote(s) Yahoo finance
Futures quote(s) Yahoo finance
ETF quote(s) Yahoo finance
Mutual fund quote(s) Yahoo finance
Historical quotes Yahoo finance
Options straddles Yahoo finance

Documentation

A neatly formatted detailed list of implementation instructions and examples will be available on the piquette website.

For now, for details on all the functionality in this library, see the GoDoc documentation.

Installation

This project supports modules and Go 1.13+. Add finance-go to your own project the usual way -

go get github.com/piquette/finance-go

Usage example

Library usage is meant to be very specific about the user's intentions.

Quote

q, err := quote.Get("AAPL")
if err != nil {
  // Uh-oh.  
  panic(err)
}

// Success!
fmt.Println(q)

Equity quote (more fields)

q, err := equity.Get("AAPL")
if err != nil {
  // Uh-oh.  
  panic(err)
}

// Success!
fmt.Println(q)

Historical quotes (OHLCV)

params := &chart.Params{
  Symbol:   "TWTR",
  Interval: datetime.OneHour,
}
iter := chart.Get(params)

for iter.Next() {
  fmt.Println(iter.Bar())
}
if err := iter.Err(); err != nil {
  fmt.Println(err)
}

Development

Pull requests from the community are welcome. If you submit one, please keep the following guidelines in mind:

  1. All types, structs and funcs should be documented.
  2. Ensure that make test succeeds.

Test

The test suite needs testify's require package to run:

github.com/stretchr/testify/require

It also depends on a running instance of a test server finance-mock, so make sure to fetch that project and run the application from another terminal session (finance-mock's README contains more information).

Docker

  docker run -p 12111:12111 piquette/finance-mock:latest

Brew

brew tap piquette/finance-mock
brew install finance-mock
finance-mock

Go

go get -u github.com/piquette/finance-mock
finance-mock

Run all tests:

go test ./...

Run tests for one package:

go test ./equity

Run a single test:

go test ./equity -run TestGet

For any requests, bug or comments, please open an issue or submit a pull request. Also please email or tweet me as needed.

Notes

  • Yahoo changes their finance APIs without warning, which is their right to do so. However, its annoying and leads to some instability in this project..
  • Big shoutout to Stripe and the team working on the stripe-go project, I took a lot of library design / implementation hints from them.