This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
account_test.go
158 lines (146 loc) · 3.43 KB
/
account_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package kumex
import (
"testing"
)
func TestApiService_AccountOverview(t *testing.T) {
s := NewApiServiceFromEnv()
p := map[string]string{}
p["currency"] = "USDT"
rsp, err := s.AccountOverview(p)
if err != nil {
t.Fatal(err)
}
o := &AccountModel{}
if err := rsp.ReadData(o); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(o))
switch {
case o.AccountEquity == 0:
t.Error("Empty key 'accountEquity'")
case o.MarginBalance < 0:
t.Error("Empty key 'marginBalance'")
case o.PositionMargin < 0:
t.Error("Empty key 'positionMargin'")
case o.OrderMargin < 0:
t.Error("Empty key 'orderMargin'")
case o.FrozenFunds < 0:
t.Error("Empty key 'frozenFunds'")
case o.AvailableBalance <= 0:
t.Error("Empty key 'availableBalance'")
case o.Currency == "":
t.Error("Empty key 'currency'")
}
}
func TestApiService_TransactionHistory(t *testing.T) {
t.SkipNow()
s := NewApiServiceFromEnv()
p := map[string]string{}
pp := &PaginationParam{CurrentPage: 1, PageSize: 10}
rsp, err := s.TransactionHistory(p, pp)
if err != nil {
t.Fatal(err)
}
ds := TransactionHistoryListModel{}
if _, err := rsp.ReadPaginationData(&ds); err != nil {
t.Fatal(err)
}
for _, d := range ds {
t.Log(ToJsonString(d))
switch {
case d.Time == "":
t.Error("Empty key 'time'")
case d.Type == "":
t.Error("Empty key 'type'")
case d.Amount == "":
t.Error("Empty key 'amount'")
case d.Status == "":
t.Error("Empty key 'status'")
case d.Fee == "":
t.Error("Empty key 'fee'")
case d.AccountEquity == "":
t.Error("Empty key 'accountEquity'")
case d.Remarks == "":
t.Error("Empty key 'remark'")
case d.Offset == "":
t.Error("Empty key 'Offset'")
}
}
}
func TestApiService_CreateSubApiKey(t *testing.T) {
t.SkipNow()
s := NewApiServiceFromEnv()
p := map[string]string{
"subName": "TestSubAccount1Fen",
"passphrase": "123abcABC",
"remark": "re",
}
rsp, err := s.CreateSubApiKey(p)
if err != nil {
t.Fatal(err)
}
w := &CreateSubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}
func TestApiService_SubApiKeys(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.SubApiKeys("", "TestSubAccount1Fen")
if err != nil {
t.Fatal(err)
}
w := SubApiKeysModel{}
if err := rsp.ReadData(&w); err != nil {
t.Fatal(err)
}
for _, model := range w {
t.Log(ToJsonString(model))
}
}
func TestApiService_ModifySubApiKey(t *testing.T) {
s := NewApiServiceFromEnv()
p := map[string]string{
"subName": "TestSubAccount1Fen",
"apiKey": "649cfa412b8f770001f5eec1",
"passphrase": "123abcABC",
"permission": "Trade",
}
rsp, err := s.ModifySubApiKey(p)
if err != nil {
t.Fatal(err)
}
w := &ModifySubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}
func TestApiService_DeleteSubApiKey(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.DeleteSubApiKey("649cfa412b8f770001f5eec1", "123abcABC", "TestSubAccount1Fen")
if err != nil {
t.Fatal(err)
}
w := &DeleteSubApiKeyRes{}
if err := rsp.ReadData(w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w))
}
func TestApiService_SubAccountsBalance(t *testing.T) {
s := NewApiServiceFromEnv()
rsp, err := s.SubAccountsBalance("USDT")
if err != nil {
t.Fatal(err)
}
w := SubAccountBalanceModel{}
if err := rsp.ReadData(&w); err != nil {
t.Fatal(err)
}
t.Log(ToJsonString(w.Summary))
for _, account := range w.Accounts {
t.Log(ToJsonString(account))
}
}