This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cryptocurrency_test.go
executable file
·95 lines (86 loc) · 2.35 KB
/
cryptocurrency_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
// NOTE: before testing, apply your CMC API key to init() of `coinmarketcap_test.go`
package coinmarketcap
import (
"testing"
"github.com/hexoul/go-coinmarketcap/types"
)
func TestCryptoInfo(t *testing.T) {
if ret, err := GetInstance().CryptoInfo(&types.Options{
Symbol: "BTC",
}); err != nil {
t.Fatal(err)
} else if ret.CryptoInfo["BTC"].Name != "Bitcoin" {
t.FailNow()
}
}
func TestCryptoMap(t *testing.T) {
if ret, err := GetInstance().CryptoMap(&types.Options{
Symbol: "BTC",
}); err != nil {
t.Fatal(err)
} else if len(ret.CryptoMap) == 0 || ret.CryptoMap[0].Name != "Bitcoin" {
t.FailNow()
}
}
func TestCryptoListingsLatest(t *testing.T) {
if listings, err := GetInstance().CryptoListingsLatest(&types.Options{
Limit: 1,
}); err != nil {
t.Fatal(err)
} else if len(listings.CryptoMarket) == 0 {
t.FailNow()
} else if listings.CryptoMarket[0].Name != "Bitcoin" {
t.FailNow()
} else if listings.CryptoMarket[0].Quote["USD"].Price <= 0 {
t.FailNow()
}
}
func TestCryptoMarketPairsLatest(t *testing.T) {
if info, err := GetInstance().CryptoMarketPairsLatest(&types.Options{
Symbol: "BTC",
}); err != nil {
t.Fatal(err)
} else if info.Name != "Bitcoin" {
t.FailNow()
}
}
func TestCryptoOhlcvLatest(t *testing.T) {
if info, err := GetInstance().CryptoOhlcvLatest(&types.Options{
Symbol: "BTC",
Convert: "USD",
}); err != nil {
t.Fatal(err)
} else if info.Ohlcv["BTC"].Name != "Bitcoin" {
t.FailNow()
} else if info.Ohlcv["BTC"].Quote["USD"] == nil {
t.FailNow()
}
}
func TestCryptoOhlcvHistorical(t *testing.T) {
if info, err := GetInstance().CryptoOhlcvHistorical(&types.Options{
Symbol: "BTC",
Convert: "USD",
TimeStart: "2018-11-12",
TimeEnd: "2018-11-13",
Interval: types.IntervalOptions.Hourly,
}); err != nil {
t.Fatal(err)
} else if info.Name != "Bitcoin" {
t.FailNow()
} else if info.Ohlcv[0].Quote["USD"] == nil {
t.FailNow()
} else if info.Ohlcv[0].Quote["USD"].Volume == 0 {
t.FailNow()
}
}
func TestCryptoMarketQuotesLatest(t *testing.T) {
if quotes, err := GetInstance().CryptoMarketQuotesLatest(&types.Options{
Symbol: "BTC,ETH",
}); err != nil {
t.Fatal(err)
} else if len(quotes.CryptoMarket) == 0 || len(quotes.CryptoMarket) != 2 {
t.FailNow()
} else if quotes.CryptoMarket["BTC"].Name != "Bitcoin" || quotes.CryptoMarket["ETH"].Name != "Ethereum" {
t.FailNow()
}
}