-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.go
51 lines (39 loc) · 1 KB
/
parser.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
41
42
43
44
45
46
47
48
49
50
51
package cryptohedge
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/cryptohazard/coinmarketcap"
)
func ParseJSON(portfolioFile string, hedgeFile string) (*Cryptofolio, *Cryptohedge) {
var crypto = new(Cryptofolio)
var hedge = new(Cryptohedge)
rawJSON, err := ioutil.ReadFile(portfolioFile)
if err != nil {
log.Fatal("Error in portfolio File ", portfolioFile, ": ", err)
}
json.Unmarshal(rawJSON, &crypto.CryptoArray)
rawJSON, err = ioutil.ReadFile(hedgeFile)
if err != nil {
log.Fatal("Error in hedge fund File ", hedgeFile, ": ", err)
}
json.Unmarshal(rawJSON, &hedge.ShareArray)
return crypto, hedge
}
func GetRate(crypto *Cryptofolio) error {
s := make([]string, len(crypto.CryptoArray))
for _, c := range crypto.CryptoArray {
s = append(s, c.Name)
}
ticker, err := coinmarketcap.GetData(s)
//fmt.Println(ticker)
if err != nil {
fmt.Println("error ticker")
return err
}
for _, c := range crypto.CryptoArray {
c.Rate = ticker.Coins[c.Name].PriceEUR
}
return nil
}