-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic_ticker.go
71 lines (62 loc) · 1.46 KB
/
public_ticker.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
63
64
65
66
67
68
69
70
71
package bitso
import (
"encoding/json"
"errors"
"fmt"
"time"
)
type TickersResponse struct {
Success bool `json:"success"`
Error Error `json:"error,omitempty"`
Tickers Tickers `json:"payload,omitempty"`
}
type TickerResponse struct {
Success bool `json:"success"`
Error Error `json:"error,omitempty"`
Ticker Ticker `json:"payload,omitempty"`
}
type Tickers []Ticker
type Ticker struct {
Book string `json:"book"`
Volume float64 `json:"volume,string"`
High float64 `json:"high,string"`
Last float64 `json:"last,string"`
Low float64 `json:"low,string"`
Vwap float64 `json:"vwap,string"`
Ask float64 `json:"ask,string"`
Bid float64 `json:"bid,string"`
CreatedAt time.Time `json:"created_at"`
}
func (api *API) Tickers() (Tickers, error) {
data, err := api.ask("ticker/", nil)
if err != nil {
return nil, err
}
ab := TickersResponse{}
err = json.Unmarshal(data, &ab)
if err != nil {
return nil, err
}
if api.Devel {
fmt.Printf("DATA RECEIVED: %+v\n", ab)
}
return ab.Tickers, nil
}
func (api *API) Ticker(book string) (*Ticker, error) {
if book == "" {
return nil, errors.New("There is no book specified")
}
data, err := api.ask("ticker/?book="+book, nil)
if err != nil {
return nil, err
}
ab := TickerResponse{}
err = json.Unmarshal(data, &ab)
if err != nil {
return nil, err
}
if api.Devel {
fmt.Printf("DATA RECEIVED: %+v\n", ab)
}
return &ab.Ticker, nil
}