forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c2c_service.go
104 lines (94 loc) · 2.69 KB
/
c2c_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
package binance
import (
"context"
"net/http"
)
// C2CTradeHistoryService retrieve c2c trade history
type C2CTradeHistoryService struct {
c *Client
tradeType SideType
startTimestamp *int64
endTimestamp *int64
page *int32
rows *int32
}
// TransactionType set transaction type
func (s *C2CTradeHistoryService) TradeType(tradeType SideType) *C2CTradeHistoryService {
s.tradeType = tradeType
return s
}
// BeginTime set beginTime
func (s *C2CTradeHistoryService) StartTimestamp(startTimestamp int64) *C2CTradeHistoryService {
s.startTimestamp = &startTimestamp
return s
}
// EndTime set endTime
func (s *C2CTradeHistoryService) EndTime(endTimestamp int64) *C2CTradeHistoryService {
s.endTimestamp = &endTimestamp
return s
}
// Page set page
func (s *C2CTradeHistoryService) Page(page int32) *C2CTradeHistoryService {
s.page = &page
return s
}
// Rows set rows
func (s *C2CTradeHistoryService) Rows(rows int32) *C2CTradeHistoryService {
s.rows = &rows
return s
}
// Do send request
func (s *C2CTradeHistoryService) Do(ctx context.Context, opts ...RequestOption) (*C2CTradeHistory, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/c2c/orderMatch/listUserOrderHistory",
secType: secTypeSigned,
}
r.setParam("tradeType", s.tradeType)
if s.startTimestamp != nil {
r.setParam("startTimestamp", *s.startTimestamp)
}
if s.endTimestamp != nil {
r.setParam("endTime", *s.endTimestamp)
}
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 := C2CTradeHistory{}
if err = json.Unmarshal(data, &res); err != nil {
return nil, err
}
return &res, nil
}
// C2CTradeHistory response
type C2CTradeHistory struct {
Code string `json:"code"`
Message string `json:"message"`
Data []C2CRecord `json:"data"`
Total int64 `json:"total"`
Success bool `json:"success"`
}
// C2CRecord a record of c2c
type C2CRecord struct {
OrderNumber string `json:"orderNumber"`
AdvNo string `json:"advNo"`
TradeType string `json:"tradeType"`
Asset string `json:"asset"`
Fiat string `json:"fiat"`
FiatSymbol string `json:"fiatSymbol"`
Amount string `json:"amount"`
TotalPrice string `json:"totalPrice"`
UnitPrice string `json:"unitPrice"`
OrderStatus string `json:"orderStatus"`
CreateTime int64 `json:"createTime"`
Commission string `json:"commission"`
CounterPartNickName string `json:"counterPartNickName"`
AdvertisementRole string `json:"advertisementRole"`
}