forked from adshao/go-binance
/
fiat_service.go
193 lines (174 loc) · 5.37 KB
/
fiat_service.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package binance
import (
"context"
"net/http"
)
// FiatDepositWithdrawHistoryService retrieve the fiat deposit/withdraw history
type FiatDepositWithdrawHistoryService struct {
c *Client
transactionType TransactionType
beginTime *int64
endTime *int64
page *int32
rows *int32
}
// TransactionType set transactionType
func (s *FiatDepositWithdrawHistoryService) TransactionType(transactionType TransactionType) *FiatDepositWithdrawHistoryService {
s.transactionType = transactionType
return s
}
// BeginTime set beginTime
func (s *FiatDepositWithdrawHistoryService) BeginTime(beginTime int64) *FiatDepositWithdrawHistoryService {
s.beginTime = &beginTime
return s
}
// EndTime set endTime
func (s *FiatDepositWithdrawHistoryService) EndTime(endTime int64) *FiatDepositWithdrawHistoryService {
s.endTime = &endTime
return s
}
// Page set page
func (s *FiatDepositWithdrawHistoryService) Page(page int32) *FiatDepositWithdrawHistoryService {
s.page = &page
return s
}
// Rows set rows
func (s *FiatDepositWithdrawHistoryService) Rows(rows int32) *FiatDepositWithdrawHistoryService {
s.rows = &rows
return s
}
// Do send request
func (s *FiatDepositWithdrawHistoryService) Do(ctx context.Context, opts ...RequestOption) (*FiatDepositWithdrawHistory, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/fiat/orders",
secType: secTypeSigned,
}
r.setParam("transactionType", s.transactionType)
if s.beginTime != nil {
r.setParam("beginTime", *s.beginTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.page != nil {
r.setParam("page", *s.page)
}
if s.rows != nil {
r.setParam("rows", *s.rows)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res := FiatDepositWithdrawHistory{}
if err = json.Unmarshal(data, &res); err != nil {
return nil, err
}
return &res, nil
}
// FiatDepositWithdrawHistory define the fiat deposit/withdraw history
type FiatDepositWithdrawHistory struct {
Code string `json:"code"`
Message string `json:"message"`
Data []FiatDepositWithdrawHistoryItem `json:"data"`
Total int32 `json:"total"`
Success bool `json:"success"`
}
// FiatDepositWithdrawHistoryItem define a fiat deposit/withdraw history item
type FiatDepositWithdrawHistoryItem struct {
OrderNo string `json:"orderNo"`
FiatCurrency string `json:"fiatCurrency"`
IndicatedAmount string `json:"indicatedAmount"`
Amount string `json:"amount"`
TotalFee string `json:"totalFee"`
Method string `json:"method"`
Status string `json:"status"`
CreateTime int64 `json:"createTime"`
UpdateTime int64 `json:"updateTime"`
}
// FiatPaymentsHistoryService retrieve the fiat payments history
type FiatPaymentsHistoryService struct {
c *Client
transactionType TransactionType
beginTime *int64
endTime *int64
page *int32
rows *int32
}
// TransactionType set transactionType
func (s *FiatPaymentsHistoryService) TransactionType(transactionType TransactionType) *FiatPaymentsHistoryService {
s.transactionType = transactionType
return s
}
// BeginTime set beginTime
func (s *FiatPaymentsHistoryService) BeginTime(beginTime int64) *FiatPaymentsHistoryService {
s.beginTime = &beginTime
return s
}
// EndTime set endTime
func (s *FiatPaymentsHistoryService) EndTime(endTime int64) *FiatPaymentsHistoryService {
s.endTime = &endTime
return s
}
// Page set page
func (s *FiatPaymentsHistoryService) Page(page int32) *FiatPaymentsHistoryService {
s.page = &page
return s
}
// Rows set rows
func (s *FiatPaymentsHistoryService) Rows(rows int32) *FiatPaymentsHistoryService {
s.rows = &rows
return s
}
// Do send request
func (s *FiatPaymentsHistoryService) Do(ctx context.Context, opts ...RequestOption) (*FiatPaymentsHistory, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/fiat/payments",
secType: secTypeSigned,
}
r.setParam("transactionType", s.transactionType)
if s.beginTime != nil {
r.setParam("beginTime", *s.beginTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.page != nil {
r.setParam("page", *s.page)
}
if s.rows != nil {
r.setParam("rows", *s.rows)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res := FiatPaymentsHistory{}
if err = json.Unmarshal(data, &res); err != nil {
return nil, err
}
return &res, nil
}
// FiatPaymentsHistory define the fiat payments history
type FiatPaymentsHistory struct {
Code string `json:"code"`
Message string `json:"message"`
Data []FiatPaymentsHistoryItem `json:"data"`
Total int32 `json:"total"`
Success bool `json:"success"`
}
// FiatPaymentsHistoryItem define a fiat payments history item
type FiatPaymentsHistoryItem struct {
OrderNo string `json:"orderNo"`
SourceAmount string `json:"sourceAmount"`
FiatCurrency string `json:"fiatCurrency"`
ObtainAmount string `json:"obtainAmount"`
CryptoCurrency string `json:"cryptoCurrency"`
TotalFee string `json:"totalFee"`
Price string `json:"price"`
Status string `json:"status"`
CreateTime int64 `json:"createTime"`
UpdateTime int64 `json:"updateTime"`
}