-
Notifications
You must be signed in to change notification settings - Fork 1
/
wealth.go
39 lines (35 loc) · 890 Bytes
/
wealth.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
package money
// Wealth an object containing assets
type Wealth struct {
Wealth []Assets `json:"wealth"`
Worth float64 `json:"worth"`
}
// Assets contain an arrah of type Asset and a catgorie
type Assets struct {
Type string `json:"type"`
Assets []Asset `json:"assets"`
}
// Asset stuct contain 1 asset type
type Asset struct {
Name string `json:"name"`
Symbol string `json:"symbol"`
Holding float64 `json:"holding"`
Worth float64 `json:"worth"`
}
// Update sets struct fields to the most recent Prices
func (w *Wealth) Update() {
var sym string
var sum float64
var hold float64
var wor float64
for i := 0; i < len(Prices); i++ {
sym = w.Wealth[1].Assets[i].Symbol
hold = w.Wealth[1].Assets[i].Holding
wor = hold * Prices[sym]
w.Wealth[1].Assets[i].Worth = wor
sum += wor
}
hold = w.Wealth[0].Assets[0].Holding
sum += hold * 0.75
w.Worth = sum
}