Financial markets data library implemented in go.

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.
Comments
  • API rate limiting for forex?

    API rate limiting for forex?

    Hi,

    Are you aware of any kind of API rate limiting for forex and Yahoo API v7? I want to retrieve every second the rates of several currency pairs.

    Thanks,

  • Missing some key statistics for Equities

    Missing some key statistics for Equities

    There are some key statistics that are missing from the stocks/equities dataset:

    • Forward Annual Dividend Rate
    • Forward Annual Dividend Yield (can be calculated based on the rate above and the price, so this one is an optional nice to have)
    • 5 Year Average Dividend Yield
    • Payout Ratio
    • Ex-Dividend Date
    • Last Split Factor
    • Last Split Date

    Any chance these missing statistics can be added?

  • added csv tags to structs

    added csv tags to structs

    This enables easy marshaling of data to CSV using https://github.com/jszwec/csvutil, though it does not add any dependency on that package. For people who don't care about CSV output, this should have no effect.

  • Actually return an error for unknown symbol

    Actually return an error for unknown symbol

    quote.Get of an inexistent symbol should return a non nil error. This does not happen.... To repro ask for a quote from a un-existant symbol:

    package main
    
    import (
      "fmt"
    
      "github.com/piquette/finance-go/quote"
    )
    
    func main() {
      q, err := quote.Get("FOOAASDADSAS") // <---- panic here because both `q` and `err` are `nil` 
      if err != nil {
        panic(err)
      }
      fmt.Printf("RegulardMarketPrice: %# +v", q.RegularMarketPrice)
    }
    
    

    This will panic:

    $ go run .
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x620b2e]
    
    goroutine 1 [running]:
    main.main()
            /home/pallotron/projects/example/ticker-quote.go:14 +0x2e
    exit status 2
    [Exit code 1 @ 10:12:01]
    

    get.Quote should return an error in this case.

  • quote.Get nil pointer dereferencing when asking quote of a inexistent symbol

    quote.Get nil pointer dereferencing when asking quote of a inexistent symbol

    Hi,

    quote.Get of an inexistent symbol should return a non nil error. This does not happen.... To repro ask for a quote from a un-existant symbol:

    package main
    
    import (
    	"fmt"
    
    	"github.com/piquette/finance-go/quote"
    )
    
    func main() {
    	q, err := quote.Get("FOOAASDADSAS")
    	if err != nil {
    		panic(err)
    	}
    	fmt.Printf("RegulardMarketPrice: %# +v", q.RegularMarketPrice)
    }
    
    

    This will panic:

    $ go run .
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x50 pc=0x620b2e]
    
    goroutine 1 [running]:
    main.main()
            /home/pallotron/projects/example/ticker-quote.go:14 +0x2e
    exit status 2
    [Exit code 1 @ 10:12:01]
    

    get.Quote should return an error in this case.

  • Is there a way to subscribe to websocket?

    Is there a way to subscribe to websocket?

    Hello. First I want to say about the greatness of this library.

    And the second: is there some way to get real-time updates of all stocks in the market ? Through websocket.

    Thank you.

  • PrevBar PrevBars methods?

    PrevBar PrevBars methods?

    Thank you for providing such great package!

    When I try to use this package, it's very convenient to fetch data, and iterate data, however, the Next() method in iter will drop all previous values. And mosts of TAs are based on previous values.

    I think it will be more convenient to change Next() (or add NextBar, NextBars method) and keep values. Also add PrevBar, PrevBars methods to get previous candle bars for technical analysis.

    What do you think? Thanks!

  • Only 1 candle for day interval

    Only 1 candle for day interval

    Hello,

    I noticed when I'm asking for chart with Interval: datetime.OneDay I always got only 1 candle which is strange... :(

    I tried this: params := &chart.Params{ Symbol: "AAPL", Interval: datetime.OneDay, } iter := chart.Get(params) for iter.Next() { b := iter.Bar() fmt.Printf("%+v %s\n", b, datetime.FromUnix(b.Timestamp).Time().Format("02.01.2006 15:04:05")) }

    What I do wrong, please?

    Regards, Max

Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Jan 2, 2023
A go port of numpy-financial functions and more.

go-financial This package is a go native port of the numpy-financial package with some additional helper functions. The functions in this package are

Dec 31, 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
Golang library for querying and parsing OFX

OFXGo OFXGo is a library for querying OFX servers and/or parsing the responses. It also provides an example command-line client to demonstrate the use

Jan 3, 2023
Payment abstraction library - one interface for multiple payment processors ( inspired by Ruby's ActiveMerchant )

Sleet Payment abstraction library - interact with different Payment Service Providers (PsP) with one unified interface. Installation go get github.com

Dec 28, 2022
Technical Analysis Library for Golang

Techan TechAn is a technical analysis library for Go! It provides a suite of tools and frameworks to analyze financial data and make trading decisions

Dec 30, 2022
Simple and easy to use client for stock market, forex and crypto data from finnhub.io written in Go. Access real-time financial market data from 60+ stock exchanges, 10 forex brokers, and 15+ crypto exchanges

go-finnhub Simple and easy to use client for stock, forex and crpyto data from finnhub.io written in Go. Access real-time market data from 60+ stock e

Dec 28, 2022
Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

go-finance Go library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds

Jan 2, 2023
A go port of numpy-financial functions and more.

go-financial This package is a go native port of the numpy-financial package with some additional helper functions. The functions in this package are

Dec 31, 2022
A distributed, proof of stake blockchain designed for the financial services industry.

Provenance Blockchain Provenance is a distributed, proof of stake blockchain designed for the financial services industry.

Dec 14, 2022
The official container networking plugin for both OECP of Alibaba Cloud and SOFAStack of Ant Financial Co.

Rama What is Rama? Rama is an open source container networking solution, integrated with Kubernetes and used officially by following well-known PaaS p

Dec 29, 2022
LINE Financial Blockchain forked from gaia

LFB(LINE Financial Blockchain) This repository hosts LFB(LINE Financial Blockchain). This repository is forked from gaia at 2021-03-15. LFB is a mainn

Dec 21, 2022
Websocket API Gateway that allows to subscribe on notifications about price changes of financial instruments

websocket-api-gateway Websocket API Gateway that allows to subscribe on notifications about price changes of financial instruments To test connection

Dec 5, 2021
Global Financial Transaction Network Services

Global Financial Transaction Network Services This code was developed at IBM during 2017-2020, and contributed to open source in September 2021. Overv

Oct 9, 2022
Desenvolvendo-Sistema-Planejamento-Financeiro-GoLang - Developing a Financial Planning System with Golang

dio-expert-session-finance Pré Desenvolvimento Vamos criar um projeto no Github

Jan 27, 2022
Diamauroa2.13.0 - Creating equitable access to the global financial system

Creating equitable access to the global financial system Diamnet Go Monorepo Thi

Feb 1, 2022
Kanzi is a modern, modular, expendable and efficient lossless data compressor implemented in Go.

kanzi Kanzi is a modern, modular, expendable and efficient lossless data compressor implemented in Go. modern: state-of-the-art algorithms are impleme

Dec 22, 2022
Data structure,Algorithms implemented in Go (for education)
 Data structure,Algorithms implemented in Go (for education)

Data structure,Algorithms implemented in Go (for education) List of Content : 1. Math - 2. String - 3. Conversions - 4. Sort - 5. Search - 6. Data str

Dec 13, 2022
Optimus is an easy-to-use, reliable, and performant workflow orchestrator for data transformation, data modeling, pipelines, and data quality management.

Optimus Optimus is an easy-to-use, reliable, and performant workflow orchestrator for data transformation, data modeling, pipelines, and data quality

Jan 6, 2023
Prometheus Common Data Exporter can parse JSON, XML, yaml or other format data from various sources (such as HTTP response message, local file, TCP response message and UDP response message) into Prometheus metric data.
Prometheus Common Data Exporter can parse JSON, XML, yaml or other format data from various sources (such as HTTP response message, local file, TCP response message and UDP response message) into Prometheus metric data.

Prometheus Common Data Exporter Prometheus Common Data Exporter 用于将多种来源(如http响应报文、本地文件、TCP响应报文、UDP响应报文)的Json、xml、yaml或其它格式的数据,解析为Prometheus metric数据。

May 18, 2022