multi
Package multi provides functionality for downloading data for multiple tickers.
Overview
The multi package allows you to efficiently download historical data for multiple stock symbols at once, with optional parallel processing.
Basic Usage
result, err := multi.Download([]string{"AAPL", "MSFT", "GOOGL"}, nil)
if err != nil {
log.Fatal(err)
}
for symbol, bars := range result.Data {
fmt.Printf("%s: %d bars\n", symbol, len(bars))
}
With Parameters
params := &models.DownloadParams{
Period: "3mo",
Interval: "1d",
Threads: 4,
}
result, err := multi.Download([]string{"AAPL", "MSFT"}, params)
Tickers Class
tickers, err := multi.NewTickers([]string{"AAPL", "MSFT", "GOOGL"})
if err != nil {
log.Fatal(err)
}
defer tickers.Close()
// Access individual ticker
aapl := tickers.Get("AAPL")
info, _ := aapl.Info()
// Download history for all
result, _ := tickers.History(nil)
Thread Safety
All multi package functions are safe for concurrent use.
Index
- func Download(symbols []string, params *models.DownloadParams) (*models.MultiTickerResult, error)
- func DownloadString(tickerStr string, params *models.DownloadParams) (*models.MultiTickerResult, error)
- type Option
- func WithClient(c *client.Client) Option
- type Tickers
- func NewTickers(symbols []string, opts ...Option) (*Tickers, error)
- func NewTickersFromString(tickerStr string, opts ...Option) (*Tickers, error)
- func (t *Tickers) Close()
- func (t *Tickers) Count() int
- func (t *Tickers) Download() (*models.MultiTickerResult, error)
- func (t *Tickers) Get(symbol string) *ticker.Ticker
- func (t *Tickers) History(params *models.DownloadParams) (*models.MultiTickerResult, error)
- func (t *Tickers) Symbols() []string
func Download
Download is a convenience function to download data for multiple tickers.
Example:
result, err := multi.Download([]string{"AAPL", "MSFT"}, nil)
if err != nil {
log.Fatal(err)
}
for symbol, bars := range result.Data {
fmt.Printf("%s: %d bars\n", symbol, len(bars))
}
func DownloadString
func DownloadString(tickerStr string, params *models.DownloadParams) (*models.MultiTickerResult, error)
DownloadString is like Download but accepts a space/comma separated string.
Example:
type Option
Option is a function that configures Tickers.
func WithClient
WithClient sets a custom HTTP client.
type Tickers
Tickers represents a collection of multiple ticker symbols.
func NewTickers
NewTickers creates a new Tickers instance for multiple symbols.
Symbols can be provided as a slice of strings.
Example:
tickers, err := multi.NewTickers([]string{"AAPL", "MSFT", "GOOGL"})
if err != nil {
log.Fatal(err)
}
defer tickers.Close()
func NewTickersFromString
NewTickersFromString creates Tickers from a space or comma separated string.
Example:
tickers, err := multi.NewTickersFromString("AAPL MSFT GOOGL")
// or
tickers, err := multi.NewTickersFromString("AAPL,MSFT,GOOGL")
func (*Tickers) Close
Close releases all resources used by Tickers.
func (*Tickers) Count
Count returns the number of tickers.
func (*Tickers) Download
Download downloads historical data for all tickers with default parameters.
func (*Tickers) Get
Get returns the Ticker instance for a specific symbol.
Returns nil if the symbol is not found.
func (*Tickers) History
History downloads historical data for all tickers.
Example:
func (*Tickers) Symbols
Symbols returns the list of ticker symbols.