quote

package module
v0.0.0-...-d942c65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 17 Imported by: 51

README

go-quote

GoDoc

A free quote downloader library and cli

Downloads daily historical price quotes from Yahoo and daily/intraday data from various api's. Written in pure Go. No external dependencies. Now downloads crypto coin historical data from various exchanges.

  • Update: 02/15/2024 - Major update: updated to Go 1.22, removed bittrex/binance support, fixed nasdaq/tiingo markets

  • Update: 11/15/2021 - Removed obsolete markets, converted to go modules

  • Update: 7/18/2021 - Removed obsolete Google support

  • Update: 6/26/2019 - updated GDAX to Coinbase, added coinbase market

  • Update: 4/26/2018 - Added preliminary tiingo CRYPTO support. Use -source=tiingo-crypto -token=<your_tingo_token> You can also set env variable TIINGO_API_TOKEN. To get symbol lists, use market: tiingo-btc, tiingo-eth or tiingo-usd

  • Update: 12/21/2017 - Added Amibroker format option (creates csv file with separate date and time). Use -format=ami

  • Update: 12/20/2017 - Added Binance exchange support. Use -source=binance

  • Update: 12/18/2017 - Added Bittrex exchange support. Use -source=bittrex

  • Update: 10/21/2017 - Added Coinbase GDAX exchange support. Use -source=gdax All times are in UTC. Automatically rate limited.

  • Update: 7/19/2017 - Added preliminary tiingo support. Use -source=tiingo -token=<your_tingo_token> You can also set env variable TIINGO_API_TOKEN

  • Update: 5/24/2017 - Now works with the new Yahoo download format. Beware - Yahoo data quality is now questionable and the free Yahoo quotes are likely to permanently go away in the near future. Use with caution!

Still very much in alpha mode. Expect bugs and API changes. Comments/suggestions/pull requests welcome!

Copyright 2024 Mark Chenoweth

Install CLI utility (quote) with:

go install github.com/markcheno/go-quote/quote@latest
Usage:
  quote -h | -help
  quote -v | -version
  quote <market> [-output=<outputFile>]
  quote [-years=<years>|(-start=<datestr> [-end=<datestr>])] [options] [-infile=<filename>|<symbol> ...]

Options:
  -h -help             show help
  -v -version          show version
  -years=<years>       number of years to download [default=5]
  -start=<datestr>     yyyy[-[mm-[dd]]]
  -end=<datestr>       yyyy[-[mm-[dd]]] [default=today]
  -infile=<filename>   list of symbols to download
  -outfile=<filename>  output filename
  -period=<period>     1m|3m|5m|15m|30m|1h|2h|4h|6h|8h|12h|d|3d|w|m [default=d]
  -source=<source>     yahoo|tiingo|tiingo-crypto|coinbase [default=yahoo]
  -token=<tiingo_tok>  tingo api token [default=TIINGO_API_TOKEN]
  -format=<format>     (csv|json|hs|ami) [default=csv]
  -adjust=<bool>       adjust yahoo prices [default=true]
  -all=<bool>          all in one file (true|false) [default=false]
  -log=<dest>          filename|stdout|stderr|discard [default=stdout]
  -delay=<ms>          delay in milliseconds between quote requests

Note: not all periods work with all sources

Valid markets:
etf,nasdaq,nasdaq100,amex,nyse,megacap,largecap,midcap,smallcap,microcap,nanocap,
telecommunications,health_care,finance,real_estate,consumer_discretionary,
consumer_staples,industrials,basic_materials,energy,utilities
coinbase,tiingo-usd,tiingo-btc,tiingo-eth

CLI Examples

# display usage
quote -help

# downloads 5 years of Yahoo SPY history to spy.csv 
quote spy

# downloads 1 year of bitcoin history to BTC-USD.csv
quote -years=1 -source=coinbase BTC-USD

# downloads 1 year of Yahoo SPY & AAPL history to quotes.csv 
quote -years=1 -all=true -outfile=quotes.csv spy aapl

# downloads full etf symbol list to etf.txt, also works for nasdaq,nasdaq100,nyse,amex
quote etf

# download fresh etf list and 5 years of etf data all in one file
quote etf && quote -all=true -outfile=etf.csv -infile=etf.txt 

Install library

Install the package with:

go get github.com/markcheno/go-quote@latest

Library example

package main

import (
	"fmt"
	"github.com/markcheno/go-quote"
	"github.com/markcheno/go-talib"
)

func main() {
	spy, _ := quote.NewQuoteFromYahoo("spy", "2016-01-01", "2016-04-01", quote.Daily, true)
	fmt.Print(spy.CSV())
	rsi2 := talib.Rsi(spy.Close, 2)
	fmt.Println(rsi2)
}

License

MIT License - see LICENSE for more details

Documentation

Overview

Package quote is free quote downloader library and cli

Downloads daily/weekly/monthly historical price quotes from Yahoo and daily/intraday data from Tiingo

Copyright 2024 Mark Chenoweth Licensed under terms of MIT license (see LICENSE)

Index

Constants

View Source
const ClientTimeout = 10 * time.Second

ClientTimeout - connect/read timeout for client requests

Variables

Delay - time delay in milliseconds between quote requests (default=100) Be nice, don't get blocked

Log - standard logger, disabled by default

View Source
var ValidMarkets = [...]string{
	"etf",
	"nasdaq",
	"nasdaq100",
	"amex",
	"nyse",
	"megacap",
	"largecap",
	"midcap",
	"smallcap",
	"microcap",
	"nanocap",
	"telecommunications",
	"health_care",
	"finance",
	"real_estate",
	"consumer_discretionary",
	"consumer_staples",
	"industrials",
	"basic_materials",
	"energy",
	"utilities",
	"technology",
	"tiingo-btc",
	"tiingo-eth",
	"tiingo-usd",
	"coinbase",
}

ValidMarkets list of markets that can be downloaded

Functions

func NewEtfFile

func NewEtfFile(filename string) error

NewEtfFile - download a list of etf symbols to a file

func NewEtfList

func NewEtfList() ([]string, error)

NewEtfList - download a list of etf symbols to an array of strings

func NewMarketFile

func NewMarketFile(market, filename string) error

NewMarketFile - download a list of market symbols to a file

func NewMarketList

func NewMarketList(market string) ([]string, error)

NewMarketList - download a list of market symbols to an array of strings

func NewSymbolsFromFile

func NewSymbolsFromFile(filename string) ([]string, error)

NewSymbolsFromFile - read symbols from a file

func ParseDateString

func ParseDateString(dt string) time.Time

ParseDateString - parse a potentially partial date string to Time

func ValidMarket

func ValidMarket(market string) bool

ValidMarket - validate market string

Types

type Period

type Period string

Period - for quote history

const (
	// Min1 - 1 Minute time period
	Min1 Period = "60"
	// Min3 - 3 Minute time period
	Min3 Period = "3m"
	// Min5 - 5 Minute time period
	Min5 Period = "300"
	// Min15 - 15 Minute time period
	Min15 Period = "900"
	// Min30 - 30 Minute time period
	Min30 Period = "1800"
	// Min60 - 60 Minute time period
	Min60 Period = "3600"
	// Hour2 - 2 hour time period
	Hour2 Period = "2h"
	// Hour4 - 4 hour time period
	Hour4 Period = "4h"
	// Hour6 - 6 hour time period
	Hour6 Period = "6h"
	// Hour8 - 8 hour time period
	Hour8 Period = "8h"
	// Hour12 - 12 hour time period
	Hour12 Period = "12h"
	// Daily time period
	Daily Period = "d"
	// Day3 - 3 day time period
	Day3 Period = "3d"
	// Weekly time period
	Weekly Period = "w"
	// Monthly time period
	Monthly Period = "m"
)

type Quote

type Quote struct {
	Symbol    string      `json:"symbol"`
	Precision int64       `json:"-"`
	Date      []time.Time `json:"date"`
	Open      []float64   `json:"open"`
	High      []float64   `json:"high"`
	Low       []float64   `json:"low"`
	Close     []float64   `json:"close"`
	Volume    []float64   `json:"volume"`
}

Quote - stucture for historical price data

func NewQuote

func NewQuote(symbol string, bars int) Quote

NewQuote - new empty Quote struct

func NewQuoteFromCSV

func NewQuoteFromCSV(symbol, csv string) (Quote, error)

NewQuoteFromCSV - parse csv quote string into Quote structure

func NewQuoteFromCSVDateFormat

func NewQuoteFromCSVDateFormat(symbol, csv string, format string) (Quote, error)

NewQuoteFromCSVDateFormat - parse csv quote string into Quote structure with specified DateTime format

func NewQuoteFromCSVFile

func NewQuoteFromCSVFile(symbol, filename string) (Quote, error)

NewQuoteFromCSVFile - parse csv quote file into Quote structure

func NewQuoteFromCSVFileDateFormat

func NewQuoteFromCSVFileDateFormat(symbol, filename string, format string) (Quote, error)

NewQuoteFromCSVFileDateFormat - parse csv quote file into Quote structure with specified DateTime format

func NewQuoteFromCoinbase

func NewQuoteFromCoinbase(symbol, startDate, endDate string, period Period) (Quote, error)

NewQuoteFromCoinbase - Coinbase Pro historical prices for a symbol

func NewQuoteFromJSON

func NewQuoteFromJSON(jsn string) (Quote, error)

NewQuoteFromJSON - parse json quote string into Quote structure

func NewQuoteFromJSONFile

func NewQuoteFromJSONFile(filename string) (Quote, error)

NewQuoteFromJSONFile - parse json quote string into Quote structure

func NewQuoteFromTiingo

func NewQuoteFromTiingo(symbol, startDate, endDate string, token string) (Quote, error)

NewQuoteFromTiingo - Tiingo daily historical prices for a symbol

func NewQuoteFromTiingoCrypto

func NewQuoteFromTiingoCrypto(symbol, startDate, endDate string, period Period, token string) (Quote, error)

NewQuoteFromTiingoCrypto - Tiingo crypto historical prices for a symbol

func NewQuoteFromYahoo

func NewQuoteFromYahoo(symbol, startDate, endDate string, period Period, adjustQuote bool) (Quote, error)

NewQuoteFromYahoo - Yahoo historical prices for a symbol

func (Quote) Amibroker

func (q Quote) Amibroker() string

Amibroker - convert Quote structure to csv string

func (Quote) CSV

func (q Quote) CSV() string

CSV - convert Quote structure to csv string

func (Quote) Highstock

func (q Quote) Highstock() string

Highstock - convert Quote structure to Highstock json format

func (Quote) JSON

func (q Quote) JSON(indent bool) string

JSON - convert Quote struct to json string

func (Quote) WriteAmibroker

func (q Quote) WriteAmibroker(filename string) error

WriteAmibroker - write Quote struct to csv file

func (Quote) WriteCSV

func (q Quote) WriteCSV(filename string) error

WriteCSV - write Quote struct to csv file

func (Quote) WriteHighstock

func (q Quote) WriteHighstock(filename string) error

WriteHighstock - write Quote struct to Highstock json format

func (Quote) WriteJSON

func (q Quote) WriteJSON(filename string, indent bool) error

WriteJSON - write Quote struct to json file

type Quotes

type Quotes []Quote

Quotes - an array of historical price data

func NewQuotesFromCSV

func NewQuotesFromCSV(csv string) (Quotes, error)

NewQuotesFromCSV - parse csv quote string into Quotes array

func NewQuotesFromCSVFile

func NewQuotesFromCSVFile(filename string) (Quotes, error)

NewQuotesFromCSVFile - parse csv quote file into Quotes array

func NewQuotesFromCoinbase

func NewQuotesFromCoinbase(filename, startDate, endDate string, period Period) (Quotes, error)

NewQuotesFromCoinbase - create a list of prices from symbols in file

func NewQuotesFromCoinbaseSyms

func NewQuotesFromCoinbaseSyms(symbols []string, startDate, endDate string, period Period) (Quotes, error)

NewQuotesFromCoinbaseSyms - create a list of prices from symbols in string array

func NewQuotesFromJSON

func NewQuotesFromJSON(jsn string) (Quotes, error)

NewQuotesFromJSON - parse json quote string into Quote structure

func NewQuotesFromJSONFile

func NewQuotesFromJSONFile(filename string) (Quotes, error)

NewQuotesFromJSONFile - parse json quote string into Quote structure

func NewQuotesFromTiingoCryptoSyms

func NewQuotesFromTiingoCryptoSyms(symbols []string, startDate, endDate string, period Period, token string) (Quotes, error)

NewQuotesFromTiingoCryptoSyms - create a list of prices from symbols in string array

func NewQuotesFromTiingoSyms

func NewQuotesFromTiingoSyms(symbols []string, startDate, endDate string, token string) (Quotes, error)

NewQuotesFromTiingoSyms - create a list of prices from symbols in string array

func NewQuotesFromYahoo

func NewQuotesFromYahoo(filename, startDate, endDate string, period Period, adjustQuote bool) (Quotes, error)

NewQuotesFromYahoo - create a list of prices from symbols in file

func NewQuotesFromYahooSyms

func NewQuotesFromYahooSyms(symbols []string, startDate, endDate string, period Period, adjustQuote bool) (Quotes, error)

NewQuotesFromYahooSyms - create a list of prices from symbols in string array

func (Quotes) Amibroker

func (q Quotes) Amibroker() string

Amibroker - convert Quotes structure to csv string

func (Quotes) CSV

func (q Quotes) CSV() string

CSV - convert Quotes structure to csv string

func (Quotes) Highstock

func (q Quotes) Highstock() string

Highstock - convert Quotes structure to Highstock json format

func (Quotes) JSON

func (q Quotes) JSON(indent bool) string

JSON - convert Quotes struct to json string

func (Quotes) WriteAmibroker

func (q Quotes) WriteAmibroker(filename string) error

WriteAmibroker - write Quotes structure to file

func (Quotes) WriteCSV

func (q Quotes) WriteCSV(filename string) error

WriteCSV - write Quotes structure to file

func (Quotes) WriteHighstock

func (q Quotes) WriteHighstock(filename string) error

WriteHighstock - write Quote struct to json file in Highstock format

func (Quotes) WriteJSON

func (q Quotes) WriteJSON(filename string, indent bool) error

WriteJSON - write Quote struct to json file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL