-
Notifications
You must be signed in to change notification settings - Fork 1
/
futures_service.go
146 lines (131 loc) · 3.59 KB
/
futures_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
package binance
import (
"context"
"encoding/json"
"net/http"
)
// FuturesTransferService transfer asset between spot account and futures account
type FuturesTransferService struct {
c *Client
asset string
amount string
transferType int
}
// Asset set asset being transferred, e.g., BTC
func (s *FuturesTransferService) Asset(asset string) *FuturesTransferService {
s.asset = asset
return s
}
// Amount the amount to be transferred
func (s *FuturesTransferService) Amount(amount string) *FuturesTransferService {
s.amount = amount
return s
}
// Type 1: transfer from spot account to futures account 2: transfer from futures account to spot account
func (s *FuturesTransferService) Type(transferType FuturesTransferType) *FuturesTransferService {
s.transferType = int(transferType)
return s
}
// Do send request
func (s *FuturesTransferService) Do(ctx context.Context, opts ...RequestOption) (res *TransactionResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/futures/transfer",
secType: secTypeSigned,
}
m := params{
"asset": s.asset,
"amount": s.amount,
"type": s.transferType,
}
r.setFormParams(m)
res = new(TransactionResponse)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// ListFuturesTransferService list futures transfer
type ListFuturesTransferService struct {
c *Client
asset string
startTime int64
endTime *int64
current *int64
size *int64
}
// Asset set asset
func (s *ListFuturesTransferService) Asset(asset string) *ListFuturesTransferService {
s.asset = asset
return s
}
// StartTime set start time
func (s *ListFuturesTransferService) StartTime(startTime int64) *ListFuturesTransferService {
s.startTime = startTime
return s
}
// EndTime set end time
func (s *ListFuturesTransferService) EndTime(endTime int64) *ListFuturesTransferService {
s.endTime = &endTime
return s
}
// Current currently querying page. Start from 1. Default:1
func (s *ListFuturesTransferService) Current(current int64) *ListFuturesTransferService {
s.current = ¤t
return s
}
// Size default:10 max:100
func (s *ListFuturesTransferService) Size(size int64) *ListFuturesTransferService {
s.size = &size
return s
}
// Do send request
func (s *ListFuturesTransferService) Do(ctx context.Context, opts ...RequestOption) (res *FuturesTransferHistory, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/futures/transfer",
secType: secTypeSigned,
}
r.setParams(params{
"asset": s.asset,
"startTime": s.startTime,
})
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.current != nil {
r.setParam("current", *s.current)
}
if s.size != nil {
r.setParam("size", *s.size)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(FuturesTransferHistory)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// FuturesTransferHistory define futures transfer history
type FuturesTransferHistory struct {
Rows []FuturesTransfer `json:"rows"`
Total int64 `json:"total"`
}
// FuturesTransfer define futures transfer history item
type FuturesTransfer struct {
Asset string `json:"asset"`
TranID int64 `json:"tranId"`
Amount string `json:"amount"`
Type int64 `json:"type"`
Timestamp int64 `json:"timestamp"`
Status FuturesTransferStatusType `json:"status"`
}