alphav

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

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

Go to latest
Published: Aug 27, 2025 License: MIT Imports: 9 Imported by: 0

README

Documentation

alphav

Provides a wrapper to the Alpha Vantage api.

The following are supported:

  • LISTING_STATUS
  • TIME_SERIES_INTRADAY
  • TIME_SERIES_DAILY_ADJUSTED (requires a premium account)
  • FX_DAILY
  • CURRENCY_EXCHANGE_RATE
  • DIVIDENDS

This allows the set of available tradeables to be retrieved, together with 20 year histories and recent intraday activity.

Note: an API KEY is required to use the API, with free keys rate limited to 25 request/day.

The package maintains a consistent behaviour across calls, for example:

func main() {
    apiKey := "MY API KEY" // Provided by some means

    ctx := alphav.Initialise(context.Background(), apiKey)

    data, err := alphav.GetIntradayData(ctx, "IBM", intraday.WithExtendedHours(false))
    if err != nil {
        fmt.Println(err)
    }

    // Do something with data
}

See examples and tests for more details.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrMissingAPIKey = errors.New("context did not contain a valid api key")

ErrMissingAPIKey returned if the api key has not been found (Initialise() not called)

Functions

func GetActiveListing

func GetActiveListing(ctx context.Context, opts ...func(*listing.Options) error) (*listing.Data, error)

GetActiveListing returns

Example
apiKey := os.Getenv("AV_API_KEY")

ctx := Initialise(context.Background(), apiKey)

if data, err := GetActiveListing(ctx, listing.WithOnlyTypes([]listing.AssetType{listing.ETF})); err == nil {
	fmt.Println(len(data.Tradeables) > 0)
} else {
	fmt.Println(err)
}
Output:

true

func GetDividendData

func GetDividendData(ctx context.Context, symbol string) (*historic.DividendData, error)

GetDividendData returns dividend data for the specified symbol, using the api_key stored in the context. Uses DIVIDENDS function - see https://www.alphavantage.co/documentation/

func GetFX

func GetFX(ctx context.Context, fromCurrency, toCurrency string, opts ...func(*fx.Options) error) (*fx.Data, error)

GetFX returns data for the specified currency pair, using the api_key stored in the context. opts allows the behaviour of the call to be varied per the options in https://www.alphavantage.co/documentation/ for FX_DAILY

Example
apiKey := os.Getenv("AV_API_KEY")

ctx := Initialise(context.Background(), apiKey)

if data, err := GetFX(ctx, "EUR", "USD", fx.WithAllAvailableHistory(false)); err == nil {
	fmt.Println(len(data.TimeSeries))
} else {
	fmt.Println(err)
}
Output:

100

func GetHistoricData

func GetHistoricData(ctx context.Context, symbol string, opts ...func(*historic.Options) error) (*historic.Data, error)

GetIntradayData returns data for the specified symbol, using the api_key stored in the context. opts allows the behaviour of the call to be varied per the options in https://www.alphavantage.co/documentation/ for TIME_SERIES_DAILY_ADJUSTED

Example
apiKey := os.Getenv("AV_API_KEY")

ctx := Initialise(context.Background(), apiKey)

if data, err := GetHistoricData(ctx, "IBM", historic.WithAllAvailableHistory(false)); err == nil {
	fmt.Println(len(data.TimeSeries))
} else {
	fmt.Println(err)
}
Output:

100

func GetIntradayData

func GetIntradayData(ctx context.Context, symbol string, opts ...func(*intraday.Options) error) (*intraday.Data, error)

GetIntradayData returns data for the specified symbol, using the api_key stored in the context. opts allows the behaviour of the call to be varied per the options in https://www.alphavantage.co/documentation/ for TIME_SERIES_INTRADAY

Example
apiKey := os.Getenv("AV_API_KEY")

ctx := Initialise(context.Background(), apiKey)

if data, err := GetIntradayData(ctx, "IBM", intraday.WithExtendedHours(false)); err == nil {
	fmt.Println(len(data.TimeSeries))
} else {
	fmt.Println(err)
}
Output:

100

func GetIntradayFX

func GetIntradayFX(ctx context.Context, fromCurrency, toCurrency string) (*fx.IntradayData, error)

GetIntradayFX returns data for the specified currency pair, using the api_key stored in the context. This uses CURRENCY_EXCHANGE_RATE from https://www.alphavantage.co/documentation/

func Initialise

func Initialise(ctx context.Context, apiKey string) context.Context

Initialise registers the supplied API Key to Alpha Vantage

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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