Giter Club home page Giter Club logo

finance-go's Introduction

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.

finance-go's People

Contributors

ackleymi avatar alai04 avatar jacks821 avatar joce avatar pallotron avatar pkaeding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finance-go's Issues

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,

Use Finnhub stock api as the new data source

Hi guys,

Big fan of Go and great project here. Just wondering if you guys are open to add https://finnhub.io/ as the new data source. Beside real-time market price (websocket supported), they also support a lot of other fundamental and alternative data for FREE.

I think this would benefit the community tremendously. With a free account, you can make 60 API requests/minute. Their documentation can be found here: https://finnhub.io/docs/api

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

Rounding in History

Here's a feature request:

Can we get a rounding capability when we pull history? I.e. if I pull symbol "MCD", I only need a quote like Open: 159.62 instead of 159.6200051825049032. Maybe "significance" variable in history.Params with constant similar to how you've done history.Interval ?

Clean up formatting

  • Remove stutter from GetHistoricalQuote
  • Run go fmt where needed
  • Ensure func comments are in golang canonical format

feature: quote for date

It seems history is highly tied to the concept of a chart. It would be helpful to support fetching a Quote for a specific historical date (or time.Time or whatever...). Is this already supported in someway I can't see?

edit: for clarity, i'm just after market close price for a specific date, which seems like it /can/ be gleaned from chart.Get(), but not without a lot of rigamarole with Params & dates.

YFinance changed their api's (or their security)

Hi.
There seams to be an issue with the finance-go, since yFinance changed its encryption keys.
Apparantly they change their encryption keys every day or even sometimes more than once a day.
This has lead to finance-go not working for a while.
yFinance has the same issue:
ranaroussi/yfinance#1407

I just wanted to bring it to your attention. I have been very happy with this library, so thank you very much for your work.

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.

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?

P/E Ratio

Thanks for the library. This works like Charm.
Is there a way to pull the P/E ratio for the stock symbol?

query all interface is error

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

// Success!
fmt.Println(q)

panic: Can't find quote for symbol: AAPL

goroutine 1 [running]:

Support Yahoo Finance API Key

Yahoo finance API is rate limited, with higher limits available if you use an API key. Would be cool to be able to plug that in when querying.

Thanks for the great library!

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!

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.