-
Notifications
You must be signed in to change notification settings - Fork 0
/
price.go
46 lines (39 loc) · 1 KB
/
price.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
package gondlr
import (
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"math/big"
"net/http"
)
func (g *Gondlr) Price(bytes string) (*big.Float, error) {
log.
WithFields(log.Fields{
"host": g.host.String(),
"network": g.network.Name(),
"publicKey": g.wallet.PublicKey(),
}).
Debugf("GET %sprice/%s/%s", g.host.String(), g.network.Name(), bytes)
req, err := http.NewRequest("GET", fmt.Sprintf("%sprice/%s/%v", g.host.String(), g.network.Name(), bytes), nil)
if err != nil {
return nil, err
}
res, err := g.httpClient.Do(req)
if res.StatusCode != http.StatusOK {
return nil, ErrorHTTP(http.StatusOK, res.StatusCode)
}
body, err := ioutil.ReadAll(res.Body)
p := new(big.Float)
if err := p.UnmarshalText(body); err != nil {
return nil, ErrorUnmarshalTextToBigInt(err)
}
log.
WithFields(log.Fields{
"host": g.host.String(),
"network": g.network.Name(),
"bytes": bytes,
"price": p.String(),
}).
Debugf("response body: %v", string(body))
return p, nil
}