README ¶
go-datareader: financial datareader
go-datareader
is a library for downloading financial data in a tabular form. It's written in Go and therefore aims to be a more performant counterpart of the Python's pandas-datareader.
The project currently supports the following data providers:
Advantages over pandas-datareader
The two main advantages of go-datareader
over it's counterpart are:
- better overall performance due to strong typing and a compiled nature of the Go programming langauge, compared to the interpreted, dynamically-typed Python
- faster data extraction due to the usage of
goroutines
to send the requests concurrently.
Getting started
Run the following command to install the go-datareader
:
$ go get -u github.com/AleksanderWWW/go-datareader
Example usage
Gather quotes for a couple of tickers from the last 100 days. The returned data is in the form of the gota dataframe. Symbols for which the data could not be obtained are omitted.
Stooq
stooqReader, err := reader.NewStooqDataReader(
[]string{"PKO", "KGH", "PZU"}, // stooq tickers
time.Now().AddDate(0, 0, -100), // start date
time.Now(), // end date
"d", // daily
)
// error handling
// ...
data := reader.GetData(stooqReader) // returns a DataFrame object
In this example the quotes are obtained in a "daily" mode. Other available options are:
- "w": weekly
- "m": monthly
- "q": quarterly
- "y": yearly
FRED
fredReader, err := reader.NewFredDataReader(
[]string{"SP500", "DJIA", "VIXCLS"},
time.Now().AddDate(0, 0, -100),
time.Now(),
)
// error handling
// ...
data := reader.GetData(fredReader)
Bank of Canada
bocReader, err := reader.NewBOCDataReader(
[]string{"FXUSDCAD", "FXCADIDR", "FXCADPEN"},
time.Now().AddDate(0, 0, -100),
time.Now(),
)
// error handling
// ...
data := reader.GetData(bocReader)
The list of available symbols can be found here.
Tiingo
startDate := time.Now().AddDate(0, 0, -4)
endDate := time.Now()
apiKey := "my-secret-api-key"
os.Setenv("TIINGO_API_KEY", apiKey) // either export the key as env variable...
tiingoReader, err := reader.NewTiingoDailyReader(
[]string{"ZZZOF", "000001"},
tiingoReader, _ := reader.NewTiingoDailyReader(
[]string{"ZZZOF", "000001"},
reader.TiingoReaderConfig{
StartDate: startDate,
EndDate: endDate,
ApiKey: apiKey // ... or pass it here.
},
)
)
// error handling
// ...
data := reader.GetData(tiingoReader)
The list of available symbols can be found here.
There are two ways to pass the Tiingo
API token - either explicitly in the TiingoReaderConfig
(takes precedence),
or via a TIINGO_API_KEY
envirionment variable (recommended option).