Skip to content

Commit f69c851

Browse files
committed
fix: dividend api change
1 parent 3794e18 commit f69c851

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

ledger/cmd/financialQuotes.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type iexDividend struct {
7272
Key string `json:"key"`
7373
Subkey string `json:"subkey"`
7474
Date int64 `json:"date"`
75-
Updated int64 `json:"updated"`
75+
Updated float64 `json:"updated"`
7676
}
7777

7878
// https://iexcloud.io/docs/api/
@@ -88,6 +88,25 @@ func stockAnnualDividends(symbol string) (amount float64, err error) {
8888
if derr != nil {
8989
return 0, derr
9090
}
91+
92+
// possible exDate issues, may get an extra
93+
if len(dividends) > 0 {
94+
switch dividends[0].Frequency {
95+
case "quarterly":
96+
if len(dividends) > 4 {
97+
dividends = dividends[:4]
98+
}
99+
case "monthly":
100+
if len(dividends) > 12 {
101+
dividends = dividends[:12]
102+
}
103+
case "semi-annual":
104+
if len(dividends) > 2 {
105+
dividends = dividends[:2]
106+
}
107+
}
108+
}
109+
91110
for _, div := range dividends {
92111
amount += div.Amount
93112
}

0 commit comments

Comments
 (0)