Categorygithub.com/TraderWithPython/finance-go
modulepackage
0.0.3
Repository: https://github.com/traderwithpython/finance-go.git
Documentation: pkg.go.dev

# README

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

DescriptionSource
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 quotesYahoo finance
Options straddlesYahoo 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/TraderWithPython/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.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

CreateArgumentError returns an error with a message about missing arguments.
CreateChartTimeError returns an error with a message improper chart arguments.
CreateRemoteError returns an error with a message about a remote api problem.
CreateRemoteErrorS returns an error with a message about a remote api problem.
GetBackend returns the currently used backend in the binding.
NewBackends creates a new set of backends with the given HTTP client.
SetBackend sets the backend used in the binding.
SetHTTPClient overrides the default HTTP client.

# Constants

BATSBackend is a constant representing the uploads service backend.
BATSURL is the URL of the uploads service backend.
MarketStateClosed closed market state.
MarketStatePost post market state.
MarketStatePostPost post-post market state.
MarketStatePre pre market state.
MarketStatePrePre pre-pre market state.
MarketStateRegular regular market state.
QuoteTypeCryptoPair the returned quote should be a crypto pair.
QuoteTypeEquity the returned quote should be an equity.
QuoteTypeETF the returned quote should be an etf.
QuoteTypeForexPair the returned quote should be a forex pair.
QuoteTypeFuture the returned quote should be a futures contract.
QuoteTypeIndex the returned quote should be an index.
QuoteTypeMutualFund the returned quote should be an mutual fund.
QuoteTypeOption the returned quote should be an option contract.
YFinBackend is a constant representing the yahoo service backend.

# Variables

Logger controls how this library performs logging at a package level.
LogLevel is the logging level for this library.
YFinURL is the URL of the yahoo service backend.
No description provided by the author
No description provided by the author

# Structs

BackendConfiguration is the internal implementation for making HTTP calls.
Backends are the currently supported endpoints.
ChartBar is a single instance of a chart bar.
ChartMeta is meta data associated with a chart response.
Contract is a struct containing a single option contract, usually part of a chain.
CryptoPair represents a single crypto currency pair quote.
Equity representa a single equity quote.
ETF represents a single etf quote.
ForexPair represents a single forex currency pair quote.
Future represents a single futures contract quote for a specified strike and expiration.
Index represents a single market Index quote.
MutualFund represents a single mutual fund share quote.
OHLCHistoric is a historical quotation.
Option represents a single option contract quote for a specified strike and expiration.
OptionsMeta is meta data associated with an options response.
Params used as a parameter to many api functions.
Quote is the basic quote structure shared across asset classes.
No description provided by the author
Straddle is a put/call straddle for a particular strike.
YfinError represents information returned in an error response.

# Interfaces

Backend is an interface for making calls against an api service.
Printfer is an interface to be implemented by Logger.

# Type aliases

No description provided by the author
No description provided by the author
SupportedBackend is an enumeration of supported api endpoints.