forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kline_service_test.go
114 lines (107 loc) · 3.18 KB
/
kline_service_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
107
108
109
110
111
112
113
114
package binance
import (
"testing"
"github.com/stretchr/testify/suite"
)
type klineServiceTestSuite struct {
baseTestSuite
}
func TestKlineService(t *testing.T) {
suite.Run(t, new(klineServiceTestSuite))
}
func (s *klineServiceTestSuite) TestKlines() {
data := []byte(`[
[
1499040000000,
"0.01634790",
"0.80000000",
"0.01575800",
"0.01577100",
"148976.11427815",
1499644799999,
"2434.19055334",
308,
"1756.87402397",
"28.46694368",
"17928899.62484339"
],
[
1499040000001,
"0.01634790",
"0.80000000",
"0.01575800",
"0.01577101",
"148976.11427815",
1499644799999,
"2434.19055334",
308,
"1756.87402397",
"28.46694368",
"17928899.62484339"
]
]`)
s.mockDo(data, nil)
defer s.assertDo()
symbol := "LTCBTC"
interval := "15m"
limit := 10
startTime := int64(1499040000000)
endTime := int64(1499040000001)
s.assertReq(func(r *request) {
e := newRequest().setParams(params{
"symbol": symbol,
"interval": interval,
"limit": limit,
"startTime": startTime,
"endTime": endTime,
})
s.assertRequestEqual(e, r)
})
klines, err := s.client.NewKlinesService().Symbol(symbol).
Interval(interval).Limit(limit).StartTime(startTime).
EndTime(endTime).Do(newContext())
s.r().NoError(err)
s.Len(klines, 2)
kline1 := &Kline{
OpenTime: 1499040000000,
Open: "0.01634790",
High: "0.80000000",
Low: "0.01575800",
Close: "0.01577100",
Volume: "148976.11427815",
CloseTime: 1499644799999,
QuoteAssetVolume: "2434.19055334",
TradeNum: 308,
TakerBuyBaseAssetVolume: "1756.87402397",
TakerBuyQuoteAssetVolume: "28.46694368",
}
kline2 := &Kline{
OpenTime: 1499040000001,
Open: "0.01634790",
High: "0.80000000",
Low: "0.01575800",
Close: "0.01577101",
Volume: "148976.11427815",
CloseTime: 1499644799999,
QuoteAssetVolume: "2434.19055334",
TradeNum: 308,
TakerBuyBaseAssetVolume: "1756.87402397",
TakerBuyQuoteAssetVolume: "28.46694368",
}
s.assertKlineEqual(kline1, klines[0])
s.assertKlineEqual(kline2, klines[1])
}
func (s *klineServiceTestSuite) assertKlineEqual(e, a *Kline) {
r := s.r()
r.Equal(e.OpenTime, a.OpenTime, "OpenTime")
r.Equal(e.Open, a.Open, "Open")
r.Equal(e.High, a.High, "High")
r.Equal(e.Low, a.Low, "Low")
r.Equal(e.Close, a.Close, "Close")
r.Equal(e.Volume, a.Volume, "Volume")
r.Equal(e.CloseTime, a.CloseTime, "CloseTime")
r.Equal(e.QuoteAssetVolume, a.QuoteAssetVolume, "QuoteAssetVolume")
r.Equal(e.TradeNum, a.TradeNum, "TradeNum")
r.Equal(e.TakerBuyBaseAssetVolume, a.TakerBuyBaseAssetVolume, "TakerBuyBaseAssetVolume")
r.Equal(e.TakerBuyQuoteAssetVolume, a.TakerBuyQuoteAssetVolume, "TakerBuyQuoteAssetVolume")
}