-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbols.go
33 lines (24 loc) · 838 Bytes
/
symbols.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package finance
import "fmt"
const symbolsURL = "http://www.batstrading.com/market_data/symbol_listing/csv/"
// GetUSEquitySymbols fetches the symbols available through BATS, ~8k symbols.
func GetUSEquitySymbols() ([]string, error) {
table, err := getSymbolsFromURL(symbolsURL)
if err != nil {
return []string{}, fmt.Errorf("error fetching symbols: (error was: %s)\n", err.Error())
}
return processSymbols(table), nil
}
// getSymbolsFromURL fetches the csv from the endpoint.
func getSymbolsFromURL(url string) (table [][]string, err error) {
return requestCSV(symbolsURL)
}
// processSymbols turns the raw table data of quotes into a slice of symbols.
func processSymbols(table [][]string) (symbols []string) {
for idx, row := range table {
if idx != 0 {
symbols = append(symbols, row[0])
}
}
return symbols
}