-
Notifications
You must be signed in to change notification settings - Fork 3
/
funding_service.go
123 lines (106 loc) · 2.57 KB
/
funding_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
package okex
import (
"context"
"encoding/json"
"net/http"
)
// Fund Transfer
// https://www.okex.com/docs-v5/en/#rest-api-funding-funds-transfer
type FundTransferService struct {
c *Client
ccy string
amt string
from string
to string
subAcct *string
instId *string
toInstId *string
transferType *string
loanTrans *bool
}
// Set Currency
func (s *FundTransferService) Currency(ccy string) *FundTransferService {
s.ccy = ccy
return s
}
// Set Amount
func (s *FundTransferService) Amount(amt string) *FundTransferService {
s.amt = amt
return s
}
// Set From
func (s *FundTransferService) From(from string) *FundTransferService {
s.from = from
return s
}
// Set To
func (s *FundTransferService) To(to string) *FundTransferService {
s.to = to
return s
}
// Set SubAccount
func (s *FundTransferService) SubAccount(subAcct string) *FundTransferService {
s.subAcct = &subAcct
return s
}
// Set Instrument Id
func (s *FundTransferService) InstrumentId(instId string) *FundTransferService {
s.instId = &instId
return s
}
// Set To Instrument Id
func (s *FundTransferService) ToInstrumentId(toInstId string) *FundTransferService {
s.toInstId = &toInstId
return s
}
// Set Transfer Type
func (s *FundTransferService) TransferType(transferType string) *FundTransferService {
s.transferType = &transferType
return s
}
// Do send request
func (s *FundTransferService) Do(ctx context.Context, opts ...RequestOption) (res *FundTransferServiceResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/api/v5/asset/transfer",
secType: secTypeSigned,
}
r.setBodyParam("ccy", s.ccy)
r.setBodyParam("amt", s.amt)
r.setBodyParam("from", s.from)
r.setBodyParam("to", s.to)
if s.subAcct != nil {
r.setBodyParam("ccy", *s.subAcct)
}
if s.instId != nil {
r.setBodyParam("instId", *s.instId)
}
if s.toInstId != nil {
r.setBodyParam("toInstId", *s.toInstId)
}
if s.transferType != nil {
r.setBodyParam("transferType", *s.transferType)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(FundTransferServiceResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
type FundTransferServiceResponse struct {
Code string `json:"code"`
Data []*FundTransferDetail `json:"data"`
Msg string `json:"msg"`
}
type FundTransferDetail struct {
TransId string `json:"transId"`
Ccy string `json:"ccy"`
From string `json:"from"`
Amt string `json:"amt"`
To string `json:"to"`
}