-
Notifications
You must be signed in to change notification settings - Fork 111
/
scheme.go
33 lines (27 loc) · 825 Bytes
/
scheme.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 mutualfund
import (
"encoding/csv"
"net/http"
"github.com/ananthakumaran/paisa/internal/model/mutualfund/scheme"
log "github.com/sirupsen/logrus"
)
func GetSchemes() ([]*scheme.Scheme, error) {
log.Info("Fetching Mutual Fund Scheme list from AMFI Website")
resp, err := http.Get("https://portal.amfiindia.com/DownloadSchemeData_Po.aspx?mf=0")
if err != nil {
return nil, err
}
defer resp.Body.Close()
reader := csv.NewReader(resp.Body)
reader.LazyQuotes = true
records, err := reader.ReadAll()
if err != nil {
return nil, err
}
var schemes []*scheme.Scheme
for _, record := range records[1:] {
scheme := scheme.Scheme{AMC: record[0], Code: record[1], Name: record[2], Type: record[3], Category: record[4], NAVName: record[5]}
schemes = append(schemes, &scheme)
}
return schemes, nil
}