-
Notifications
You must be signed in to change notification settings - Fork 2
/
futures_service_test.go
109 lines (99 loc) · 2.61 KB
/
futures_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
package binance
import (
"testing"
"github.com/crypto-zero/go-binance/v2/common"
"github.com/stretchr/testify/suite"
)
type futuresTransferTestSuite struct {
baseTestSuite
}
func TestFuturesTransferService(t *testing.T) {
suite.Run(t, new(futuresTransferTestSuite))
}
func (s *futuresTransferTestSuite) TestTransfer() {
data := []byte(`{
"tranId": 100000001
}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "BTC"
amount := "1.000"
transferType := FuturesTransferTypeSpotToFutures
s.assertReq(func(r *common.Request) {
e := newSignedRequest().SetFormParams(common.Params{
"asset": asset,
"amount": amount,
"type": transferType,
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewFuturesTransferService().Asset(asset).
Amount(amount).Type(transferType).Do(newContext())
s.r().NoError(err)
e := &TransactionResponse{
TranID: 100000001,
}
s.assertTransactionResponseEqual(e, res)
}
func (s *futuresTransferTestSuite) assertTransactionResponseEqual(a, e *TransactionResponse) {
s.r().Equal(a.TranID, e.TranID, "TranID")
}
func (s *futuresTransferTestSuite) TestListFuturesTransfer() {
data := []byte(`{
"rows": [
{
"asset": "USDT",
"tranId": 100000001,
"amount": "40.84624400",
"type": 1,
"timestamp": 1555056425000,
"status": "CONFIRMED"
}
],
"total": 1
}`)
s.mockDo(data, nil)
defer s.assertDo()
asset := "USDT"
startTime := int64(1555056425000)
s.assertReq(func(r *common.Request) {
e := newSignedRequest().SetQueryParams(common.Params{
"asset": asset,
"startTime": startTime,
})
s.assertRequestEqual(e, r)
})
res, err := s.client.NewListFuturesTransferService().Asset(asset).
StartTime(startTime).Do(newContext())
s.r().NoError(err)
e := &FuturesTransferHistory{
Rows: []FuturesTransfer{
{
Asset: asset,
TranID: int64(100000001),
Amount: "40.84624400",
Type: 1,
Timestamp: int64(1555056425000),
Status: FuturesTransferStatusTypeConfirmed,
},
},
Total: 1,
}
s.assertFuturesTransferHistoryEqual(e, res)
}
func (s *futuresTransferTestSuite) assertFuturesTransferHistoryEqual(e, a *FuturesTransferHistory) {
s.r().Equal(e.Total, a.Total, "Total")
s.r().Len(a.Rows, len(e.Rows))
for i := range a.Rows {
s.assertFuturesTransferEqual(e.Rows[i], a.Rows[i])
}
}
func (s *futuresTransferTestSuite) assertFuturesTransferEqual(e, a FuturesTransfer) {
r := s.r()
r.Equal(e.Asset, a.Asset, "Asset")
r.Equal(e.TranID, a.TranID, "TranID")
r.Equal(e.Amount, a.Amount, "Amount")
r.Equal(e.Type, a.Type, "Type")
r.Equal(e.Timestamp, a.Timestamp, "Timestamp")
r.Equal(e.Status, a.Status, "Status")
}