-
Notifications
You must be signed in to change notification settings - Fork 2
/
depth_service_test.go
79 lines (72 loc) · 1.71 KB
/
depth_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
package binance
import (
"testing"
"github.com/crypto-zero/go-binance/v2/common"
"github.com/stretchr/testify/suite"
)
type depthServiceTestSuite struct {
baseTestSuite
}
func TestDepthService(t *testing.T) {
suite.Run(t, new(depthServiceTestSuite))
}
func (s *depthServiceTestSuite) TestDepth() {
data := []byte(`{
"lastUpdateId": 1027024,
"bids": [
[
"4.00000000",
"431.00000000",
[]
]
],
"asks": [
[
"4.00000200",
"12.00000000",
[]
]
]
}`)
s.mockDo(data, nil)
defer s.assertDo()
symbol := "LTCBTC"
limit := 3
s.assertReq(func(r *common.Request) {
e := newRequest().SetQuery("symbol", symbol).
SetQuery("limit", limit)
s.assertRequestEqual(e, r)
})
res, err := s.client.NewDepthService().Symbol(symbol).Limit(limit).Do(newContext())
s.r().NoError(err)
e := &DepthResponse{
LastUpdateID: 1027024,
Bids: []Bid{
{
Price: "4.00000000",
Quantity: "431.00000000",
},
},
Asks: []Ask{
{
Price: "4.00000200",
Quantity: "12.00000000",
},
},
}
s.assertDepthResponseEqual(e, res)
}
func (s *depthServiceTestSuite) assertDepthResponseEqual(e, a *DepthResponse) {
r := s.r()
r.Equal(e.LastUpdateID, a.LastUpdateID, "LastUpdateID")
r.Len(a.Bids, len(e.Bids))
for i := 0; i < len(a.Bids); i++ {
r.Equal(e.Bids[i].Price, a.Bids[i].Price, "Price")
r.Equal(e.Bids[i].Quantity, a.Bids[i].Quantity, "Quantity")
}
r.Len(a.Asks, len(e.Asks))
for i := 0; i < len(a.Asks); i++ {
r.Equal(e.Asks[i].Price, a.Asks[i].Price, "Price")
r.Equal(e.Asks[i].Quantity, a.Asks[i].Quantity, "Quantity")
}
}