forked from preichenberger/go-coinbasepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product_test.go
106 lines (89 loc) · 1.95 KB
/
product_test.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package coinbasepro
import (
"errors"
"testing"
)
func TestGetProducts(t *testing.T) {
client := NewTestClient()
products, err := client.GetProducts()
if err != nil {
t.Error(err)
}
for _, p := range products {
if StructHasZeroValues(p) && p.StatusMessage != "" {
t.Error(errors.New("Zero value"))
}
}
}
func TestGetBook(t *testing.T) {
client := NewTestClient()
_, err := client.GetBook("BTC-USD", 1)
if err != nil {
t.Error(err)
}
_, err = client.GetBook("BTC-USD", 2)
if err != nil {
t.Error(err)
}
_, err = client.GetBook("BTC-USD", 3)
if err != nil {
t.Error(err)
}
}
func TestGetTicker(t *testing.T) {
client := NewTestClient()
ticker, err := client.GetTicker("BTC-USD")
if err != nil {
t.Error(err)
}
if StructHasZeroValues(ticker) {
t.Error(errors.New("Zero value"))
}
ticker, err = client.GetTicker("ETH-BTC")
if err != nil {
t.Error(err)
}
if StructHasZeroValues(ticker) {
t.Error(errors.New("Zero value"))
}
}
func TestListTrades(t *testing.T) {
var trades []Trade
client := NewTestClient()
cursor := client.ListTrades("BTC-USD")
if err := cursor.NextPage(&trades); err != nil {
t.Error(err)
}
for _, a := range trades {
if StructHasZeroValues(a) {
t.Error(errors.New("Zero value"))
}
}
}
func TestGetHistoricRates(t *testing.T) {
// Disabled due to error on sandbox
return
client := NewTestClient()
params := GetHistoricRatesParams{
Granularity: 3600,
}
historicRates, err := client.GetHistoricRates("BTC-USD", params)
if err != nil {
t.Error(err)
}
props := []string{"Time", "Low", "High", "Open", "Close", "Volume"}
if err := EnsureProperties(historicRates[0], props); err != nil {
t.Error(err)
}
}
func TestGetStats(t *testing.T) {
client := NewTestClient()
stats, err := client.GetStats("BTC-USD")
if err != nil {
t.Error(err)
}
props := []string{"Low", "Open", "Volume", "Last", "Volume30Day"}
if err := EnsureProperties(stats, props); err != nil {
t.Error(err)
}
}