-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassets.go
37 lines (30 loc) · 973 Bytes
/
assets.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
package main
import (
"fmt"
"strings"
)
//Asset struct
type Asset struct {
Name string
Ticker string
Qty float64
BTCPrice float64 //current BTC price
FiatPrice float64 //current fiat price
}
//Assets array struct
type Assets []Asset
//PrintAssets used for simple portfolio view
func PrintAssets(assets Assets) {
var totalBTCValue, totalFiatValue float64
fmt.Println(strings.Repeat("-", 53))
fmt.Printf("|%11s|%6s|%11s|%8s|%11s|\n", "Name", "Ticker", "Quantity", "BTCPrice", Config.BaseCurrency)
for _, coin := range assets {
fmt.Printf("|%11s|%6s|%11.03f|%8f|%11.2f|\n", coin.Name, coin.Ticker, coin.Qty, coin.BTCPrice, coin.FiatPrice)
totalBTCValue += coin.Qty * coin.BTCPrice
totalFiatValue += coin.Qty * coin.FiatPrice
}
fmt.Println(strings.Repeat("-", 53))
fmt.Printf("Total value : %.8f BTC\n", totalBTCValue)
fmt.Printf("Total value : %.2f %s\n", totalFiatValue, Config.BaseCurrency)
fmt.Println(strings.Repeat("-", 53))
}