-
Notifications
You must be signed in to change notification settings - Fork 0
/
Getdata_yf.go
executable file
·40 lines (35 loc) · 1.02 KB
/
Getdata_yf.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
34
35
36
37
38
39
40
package main
import (
"github.com/piquette/finance-go/chart"
"github.com/piquette/finance-go/datetime"
"time"
)
func Getdata_yf(symbol string, start time.Time, end time.Time) (map[string]map[string]float64, error) {
params := &chart.Params{
Symbol: symbol,
Interval: datetime.OneDay,
Start: datetime.New(&start),
End: datetime.New(&end),
}
iter := chart.Get(params)
data := make(map[string]map[string]float64)
for iter.Next() {
bar := iter.Bar()
bartime := time.Unix(int64(bar.Timestamp), 0)
formmatedTime := bartime.Format("2006-01-02")
if _, ok := data[formmatedTime]; !ok {
data[formmatedTime] = make(map[string]float64)
}
if bar.Volume > 0 {
data[formmatedTime]["Open"], _ = bar.Open.Float64()
data[formmatedTime]["High"], _ = bar.High.Float64()
data[formmatedTime]["Low"], _ = bar.Low.Float64()
data[formmatedTime]["Close"], _ = bar.AdjClose.Float64()
data[formmatedTime]["Volume"] = float64(bar.Volume)
}
}
if iter.Err() != nil {
return nil, iter.Err()
}
return data, nil
}