alphavantage

package module
v0.0.0-...-96315dc Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 17 Imported by: 1

README

alphavantage - Alpha Vantage API in Go

GoDoc

Table of Contents

Apply

Installation

$ go get github.com/z-Wind/alphavantage

Examples

Client
client := GetClient(apikey)
av, err := New(client)
Timeseries
call := av.TimeSeries.Intraday("VTI", TimeSeriesIntervalOneMinute)
timeSeriesList, err := call.Do()

Todo

  • Foreign Exchange
  • Digital Crypto Currencies
  • Technical Indicators
  • Sector Performances

Reference

Documentation

Index

Examples

Constants

View Source
const (
	// Version defines the gax version being used. This is typically sent
	// in an HTTP header to services.
	Version = "0.5"

	// UserAgent is the header string used to identify this package.
	UserAgent = "alphavantage-api-go-client/" + Version
)
View Source
const (
	TimeSeriesIntervalOneMinute     = "1min"
	TimeSeriesIntervalFiveMinute    = "5min"
	TimeSeriesIntervalFifteenMinute = "15min"
	TimeSeriesIntervalThirtyMinute  = "30min"
	TimeSeriesIntervalOneHour       = "60min"
	OutputSizeFull                  = "full"
	OutputsizeCompact               = "compact"
)

Stock Time Series

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(res *http.Response) error

CheckResponse returns an error (of type *Error) if the response status code is not 2xx.

func DecodeResponseCSV

func DecodeResponseCSV(target interface{}, res *http.Response) error

DecodeResponseCSV decodes the body of res into target. If there is no body, target is unchanged.

func DecodeResponseJSON

func DecodeResponseJSON(target interface{}, res *http.Response) error

DecodeResponseJSON decodes the body of res into target. If there is no body, target is unchanged.

func GetClient

func GetClient(key string) *http.Client

GetClient get client which could append apikey

func JSONReader

func JSONReader(v interface{}) (io.Reader, error)

JSONReader convert struct to reader for json request

func ResolveRelative

func ResolveRelative(basePath string, elem ...string) string

ResolveRelative join path

func SendRequest

func SendRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)

SendRequest sends a single HTTP request using the given client. If ctx is non-nil, it sends the request with req.WithContext

Types

type DefaultCall

type DefaultCall struct {
	// contains filtered or unexported fields
}

DefaultCall DefaultCall function

func (*DefaultCall) Context

func (c *DefaultCall) Context(ctx context.Context) *DefaultCall

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DefaultCall) Header

func (c *DefaultCall) Header() http.Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DigitalCryptoCurrenciesService

type DigitalCryptoCurrenciesService struct {
	// contains filtered or unexported fields
}

DigitalCryptoCurrenciesService https://www.alphavantage.co/documentation/#digital-currency APIs under this section provide a wide range of data feed for digital and crypto currencies such as Bitcoin.

func NewDigitalCryptoCurrenciesService

func NewDigitalCryptoCurrenciesService(s *Service) *DigitalCryptoCurrenciesService

NewDigitalCryptoCurrenciesService https://www.alphavantage.co/documentation/#digital-currency APIs under this section provide a wide range of data feed for digital and crypto currencies such as Bitcoin.

type Error

type Error struct {
	// Code is the HTTP response status code and will always be populated.
	Code int `json:"code,omitempty"`
	// Message is the server response message and is only populated when
	// explicitly referenced by the JSON server response.
	Message string `json:"message,omitempty"`
	// Body is the raw response returned by the server.
	// It is often but not always JSON, depending on how the request fails.
	Body string
	// Header contains the response header fields from the server.
	Header http.Header
}

Error contains an error response from the server.

func (*Error) Error

func (e *Error) Error() string

type ForeignExchangeService

type ForeignExchangeService struct {
	// contains filtered or unexported fields
}

ForeignExchangeService https://www.alphavantage.co/documentation/#symbolsearch APIs under this section provide a wide range of data feed for realtime and historical forex (FX) rates.

func NewForeignExchangeService

func NewForeignExchangeService(s *Service) *ForeignExchangeService

NewForeignExchangeService https://www.alphavantage.co/documentation/#symbolsearch APIs under this section provide a wide range of data feed for realtime and historical forex (FX) rates.

type Percent

type Percent float64

Percent redefine for percent value

func (*Percent) UnmarshalCSV

func (p *Percent) UnmarshalCSV(data []byte) error

UnmarshalCSV parse data

type Quote

type Quote struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `csv:"-"`

	Symbol        string  `csv:"symbol"`
	Open          float64 `csv:"open"`
	High          float64 `csv:"high"`
	Low           float64 `csv:"low"`
	Price         float64 `csv:"price"`
	Volume        float64 `csv:"volume"`
	LatestDay     Time    `csv:"latestDay"`
	PreviousClose float64 `csv:"previousClose"`
	Change        float64 `csv:"change"`
	ChangePercent Percent `csv:"changePercent"`
}

Quote Quote

type SearchResult

type SearchResult struct {
	Symbol      string  `csv:"symbol"`
	Name        string  `csv:"name"`
	Type        string  `csv:"type"`
	Region      string  `csv:"region"`
	MarketOpen  string  `csv:"marketOpen"`
	MarketClose string  `csv:"marketClose"`
	Timezone    string  `csv:"timezone"`
	Currency    string  `csv:"currency"`
	MatchScore  float64 `csv:"matchScore"`
}

SearchResult SearchResult

type SearchResultList

type SearchResultList struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `csv:"-"`

	SearchResults []*SearchResult
}

SearchResultList Search Result List

type SectorPerformancesService

type SectorPerformancesService struct {
	// contains filtered or unexported fields
}

SectorPerformancesService https://www.alphavantage.co/documentation/#sector-information This API returns the realtime and historical sector performances calculated from S&P500 incumbents.

func NewSectorPerformancesService

func NewSectorPerformancesService(s *Service) *SectorPerformancesService

NewSectorPerformancesService https://www.alphavantage.co/documentation/#sector-information This API returns the realtime and historical sector performances calculated from S&P500 incumbents.

type ServerResponse

type ServerResponse struct {
	// HTTPStatusCode is the server's response status code. When using a
	// resource method's Do call, this will always be in the 2xx range.
	HTTPStatusCode int
	// Header contains the response header fields from the server.
	Header http.Header
}

ServerResponse is embedded in each Do response and provides the HTTP status code and header sent by the server.

type Service

type Service struct {
	BasePath  string // API endpoint base URL
	UserAgent string // optional additional User-Agent fragment

	TimeSeries              *TimeSeriesService
	ForeignExchange         *ForeignExchangeService
	DigitalCryptoCurrencies *DigitalCryptoCurrenciesService
	TechnicalIndicators     *TechnicalIndicatorsService
	SectorPerformances      *SectorPerformancesService
	// contains filtered or unexported fields
}

Service Alpha Vantage api

func New

func New(client *http.Client) (*Service, error)

New AlphaVantage API server

type TechnicalIndicatorsService

type TechnicalIndicatorsService struct {
	// contains filtered or unexported fields
}

TechnicalIndicatorsService https://www.alphavantage.co/documentation/#technical-indicators Technical indicator values are updated realtime: the latest data point is derived from the current trading day of a given equity or currency exchange pair.

func NewTechnicalIndicatorsService

func NewTechnicalIndicatorsService(s *Service) *TechnicalIndicatorsService

NewTechnicalIndicatorsService https://www.alphavantage.co/documentation/#technical-indicators Technical indicator values are updated realtime: the latest data point is derived from the current trading day of a given equity or currency exchange pair.

type Time

type Time time.Time

Time redefine time.time for Unmarshal

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalCSV

func (t *Time) UnmarshalCSV(data []byte) error

UnmarshalCSV process Date

type TimeSeries

type TimeSeries struct {
	Time   Time    `csv:"timestamp"`
	Open   float64 `csv:"open"`
	High   float64 `csv:"high"`
	Low    float64 `csv:"low"`
	Close  float64 `csv:"close"`
	Volume float64 `csv:"volume"`

	// adj
	AdjustedClose    float64 `csv:"adjusted_close,omitempty"`
	DividendAmount   float64 `csv:"dividend_amount,omitempty"`
	SplitCoefficient float64 `csv:"split_coefficient,omitempty"`
}

TimeSeries time series

type TimeSeriesDailyAdjCall

type TimeSeriesDailyAdjCall struct {
	DefaultCall
}

TimeSeriesDailyAdjCall https://www.alphavantage.co/documentation/#DailyAdj This API returns daily time series (date, daily open, daily high, daily low, daily close, daily volume, daily adjusted close, and split/dividend events) of the global equity specified, covering 20+ years of historical data. The most recent data point is the prices and volume information of the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesDailyAdjCall) Do

Do send request

func (*TimeSeriesDailyAdjCall) Outputsize

func (c *TimeSeriesDailyAdjCall) Outputsize(outputsize string) *TimeSeriesDailyAdjCall

Outputsize By default, outputsize=compact. Strings compact and full are accepted with the following specifications: compact returns only the latest 100 data points; full returns the full-length time series of 20+ years of historical data. The "compact" option is recommended if you would like to reduce the data size of each API call.

type TimeSeriesDailyCall

type TimeSeriesDailyCall struct {
	DefaultCall
}

TimeSeriesDailyCall https://www.alphavantage.co/documentation/#daily This API returns daily time series (date, daily open, daily high, daily low, daily close, daily volume) of the global equity specified, covering 20+ years of historical data. The most recent data point is the prices and volume information of the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesDailyCall) Do

Do send request

func (*TimeSeriesDailyCall) Outputsize

func (c *TimeSeriesDailyCall) Outputsize(outputsize string) *TimeSeriesDailyCall

Outputsize By default, outputsize=compact. Strings compact and full are accepted with the following specifications: compact returns only the latest 100 data points; full returns the full-length time series of 20+ years of historical data. The "compact" option is recommended if you would like to reduce the data size of each API call.

type TimeSeriesIntradayCall

type TimeSeriesIntradayCall struct {
	DefaultCall
}

TimeSeriesIntradayCall https://www.alphavantage.co/documentation/#intraday This API returns intraday time series (timestamp, open, high, low, close, volume) of the equity specified. datatype fixed to csv

func (*TimeSeriesIntradayCall) Do

Do send request

func (*TimeSeriesIntradayCall) Outputsize

func (c *TimeSeriesIntradayCall) Outputsize(outputsize string) *TimeSeriesIntradayCall

Outputsize By default, outputsize=compact. Strings compact and full are accepted with the following specifications: compact returns only the latest 100 data points; full returns the full-length time series of 20+ years of historical data. The "compact" option is recommended if you would like to reduce the data size of each API call.

type TimeSeriesList

type TimeSeriesList struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `csv:"-"`

	TimeSeries []*TimeSeries
}

TimeSeriesList TimeSeries List

type TimeSeriesMonthlyAdjCall

type TimeSeriesMonthlyAdjCall struct {
	DefaultCall
}

TimeSeriesMonthlyAdjCall https://www.alphavantage.co/documentation/#monthlyadj This API returns monthly adjusted time series (last trading day of each month, monthly open, monthly high, monthly low, monthly close, monthly adjusted close, monthly volume, monthly dividend) of the equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the month (or partial month) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesMonthlyAdjCall) Do

Do send request

type TimeSeriesMonthlyCall

type TimeSeriesMonthlyCall struct {
	DefaultCall
}

TimeSeriesMonthlyCall https://www.alphavantage.co/documentation/#monthly This API returns monthly time series (last trading day of each month, monthly open, monthly high, monthly low, monthly close, monthly volume) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the month (or partial month) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesMonthlyCall) Do

Do send request

type TimeSeriesQuoteEndpointCall

type TimeSeriesQuoteEndpointCall struct {
	DefaultCall
	// contains filtered or unexported fields
}

TimeSeriesQuoteEndpointCall https://www.alphavantage.co/documentation/#latestprice A lightweight alternative to the time series APIs, this service returns the latest price and volume information for a security of your choice. datatype fixed to csv

func (*TimeSeriesQuoteEndpointCall) Do

Do send request

type TimeSeriesSearchEndpointCall

type TimeSeriesSearchEndpointCall struct {
	DefaultCall
}

TimeSeriesSearchEndpointCall https://www.alphavantage.co/documentation/#symbolsearch We've got you covered! The Search Endpoint returns the best-matching symbols and market information based on keywords of your choice. The search results also contain match scores that provide you with the full flexibility to develop your own search and filtering logic. datatype fixed to csv

func (*TimeSeriesSearchEndpointCall) Do

Do send request

type TimeSeriesService

type TimeSeriesService struct {
	// contains filtered or unexported fields
}

TimeSeriesService https://www.alphavantage.co/documentation/#time-series-data This suite of APIs provide realtime and historical global equity data in 4 different temporal resolutions: (1) daily, (2) weekly, (3) monthly, and (4) intraday. Daily, weekly, and monthly time series contain 20+ years of historical data.

func NewTimeSeriesService

func NewTimeSeriesService(s *Service) *TimeSeriesService

NewTimeSeriesService https://www.alphavantage.co/documentation/#time-series-data This suite of APIs provide realtime and historical global equity data in 4 different temporal resolutions: (1) daily, (2) weekly, (3) monthly, and (4) intraday. Daily, weekly, and monthly time series contain 20+ years of historical data.

func (*TimeSeriesService) Daily

func (r *TimeSeriesService) Daily(symbol string) *TimeSeriesDailyCall

Daily https://www.alphavantage.co/documentation/#daily This API returns daily time series (date, daily open, daily high, daily low, daily close, daily volume) of the global equity specified, covering 20+ years of historical data. The most recent data point is the prices and volume information of the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesService) DailyAdj

func (r *TimeSeriesService) DailyAdj(symbol string) *TimeSeriesDailyAdjCall

DailyAdj https://www.alphavantage.co/documentation/#dailyadj This API returns daily time series (date, daily open, daily high, daily low, daily close, daily volume, daily adjusted close, and split/dividend events) of the global equity specified, covering 20+ years of historical data. The most recent data point is the prices and volume information of the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesService) Intraday

func (r *TimeSeriesService) Intraday(symbol, interval string) *TimeSeriesIntradayCall

Intraday https://www.alphavantage.co/documentation/#intraday This API returns intraday time series (timestamp, open, high, low, close, volume) of the equity specified. datatype fixed to csv

Example
client := GetClient(randkey(keyLen))

var err error
avReal, err = New(client)
if err != nil {
	log.Fatal(err)
}

IntradayCall := avReal.TimeSeries.Intraday("VTI", TimeSeriesIntervalOneMinute)
timeSeriesList, err := IntradayCall.Do()
if err != nil {
	log.Fatal(err)
}

fmt.Printf("%v", timeSeriesList.TimeSeries)
Output:

func (*TimeSeriesService) Monthly

func (r *TimeSeriesService) Monthly(symbol string) *TimeSeriesMonthlyCall

Monthly https://www.alphavantage.co/documentation/#monthly This API returns monthly time series (last trading day of each month, monthly open, monthly high, monthly low, monthly close, monthly volume) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the month (or partial month) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesService) MonthlyAdj

func (r *TimeSeriesService) MonthlyAdj(symbol string) *TimeSeriesMonthlyAdjCall

MonthlyAdj https://www.alphavantage.co/documentation/#monthlyadj This API returns monthly adjusted time series (last trading day of each month, monthly open, monthly high, monthly low, monthly close, monthly adjusted close, monthly volume, monthly dividend) of the equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the month (or partial month) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesService) QuoteEndpoint

func (r *TimeSeriesService) QuoteEndpoint(symbol string) *TimeSeriesQuoteEndpointCall

QuoteEndpoint https://www.alphavantage.co/documentation/#latestprice A lightweight alternative to the time series APIs, this service returns the latest price and volume information for a security of your choice. datatype fixed to csv

func (*TimeSeriesService) SearchEndpoint

func (r *TimeSeriesService) SearchEndpoint(keywords string) *TimeSeriesSearchEndpointCall

SearchEndpoint https://www.alphavantage.co/documentation/#symbolsearch We've got you covered! The Search Endpoint returns the best-matching symbols and market information based on keywords of your choice. The search results also contain match scores that provide you with the full flexibility to develop your own search and filtering logic. datatype fixed to csv

func (*TimeSeriesService) Weekly

func (r *TimeSeriesService) Weekly(symbol string) *TimeSeriesWeeklyCall

Weekly https://www.alphavantage.co/documentation/#weekly This API returns weekly time series (last trading day of each week, weekly open, weekly high, weekly low, weekly close, weekly volume) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the week (or partial week) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesService) WeeklyAdj

func (r *TimeSeriesService) WeeklyAdj(symbol string) *TimeSeriesWeeklyAdjCall

WeeklyAdj https://www.alphavantage.co/documentation/#weeklyadj This API returns weekly adjusted time series (last trading day of each week, weekly open, weekly high, weekly low, weekly close, weekly adjusted close, weekly volume, weekly dividend) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the week (or partial week) that contains the current trading day, updated realtime. datatype fixed to csv

type TimeSeriesWeeklyAdjCall

type TimeSeriesWeeklyAdjCall struct {
	DefaultCall
}

TimeSeriesWeeklyAdjCall https://www.alphavantage.co/documentation/#weeklyadj This API returns weekly adjusted time series (last trading day of each week, weekly open, weekly high, weekly low, weekly close, weekly adjusted close, weekly volume, weekly dividend) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the week (or partial week) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesWeeklyAdjCall) Do

Do send request

type TimeSeriesWeeklyCall

type TimeSeriesWeeklyCall struct {
	DefaultCall
}

TimeSeriesWeeklyCall https://www.alphavantage.co/documentation/#weekly This API returns weekly time series (last trading day of each week, weekly open, weekly high, weekly low, weekly close, weekly volume) of the global equity specified, covering 20+ years of historical data. The latest data point is the prices and volume information for the week (or partial week) that contains the current trading day, updated realtime. datatype fixed to csv

func (*TimeSeriesWeeklyCall) Do

Do send request

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport add apikey

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip add apikey

Jump to

Keyboard shortcuts

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