forked from asuleymanov/steem-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.go
62 lines (49 loc) · 1.41 KB
/
convert.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
52
53
54
55
56
57
58
59
60
61
62
package rpc
import (
"strconv"
"strings"
)
//SbdMedianPrice returns the average cost of GBG when converting GOLOS.
func (client *Client) SbdMedianPrice() (float64, error) {
smpreq, errsmp := client.Database.GetFeedHistory()
if errsmp != nil {
return 0, errsmp
}
base, errbase := strconv.ParseFloat(strings.Split(smpreq.CurrentMedianHistory.Base, " ")[0], 64)
if errbase != nil {
return 0, errbase
}
quote, errquote := strconv.ParseFloat(strings.Split(smpreq.CurrentMedianHistory.Quote, " ")[0], 64)
if errquote != nil {
return 0, errquote
}
smptmp := base / quote
str := strconv.FormatFloat(smptmp, 'f', 3, 64)
smp, errsmp := strconv.ParseFloat(str, 64)
if errsmp != nil {
return 0, errsmp
}
return smp, nil
}
//SteemPerMvest returns the ratio of TotalVersingFundSteem to TotalVestingShares.
func (client *Client) SteemPerMvest() (float64, error) {
dgp, errdgp := client.Database.GetDynamicGlobalProperties()
if errdgp != nil {
return 0, errdgp
}
tvfs, errtvfs := strconv.ParseFloat(strings.Split(dgp.TotalVersingFundSteem, " ")[0], 64)
if errtvfs != nil {
return 0, errtvfs
}
tvs, errtvs := strconv.ParseFloat(strings.Split(dgp.TotalVestingShares, " ")[0], 64)
if errtvs != nil {
return 0, errtvs
}
spmtmp := (tvfs / tvs) * 1000000
str := strconv.FormatFloat(spmtmp, 'f', 3, 64)
spm, errspm := strconv.ParseFloat(str, 64)
if errspm != nil {
return 0, errspm
}
return spm, nil
}