-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunding.go
183 lines (151 loc) · 4.62 KB
/
funding.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
package gokraken
import (
"context"
"net/http"
"net/url"
"strconv"
"github.com/danmrichards/gokraken/asset"
)
// Funding is responsible for communicating with all the private user funding
// endpoints on the Kraken API.
type Funding struct {
Client *Kraken
}
// DepositMethods gets a list of deposit methods via the Kraken API.
// https://www.kraken.com/en-gb/help/api#deposit-methods
func (f *Funding) DepositMethods(ctx context.Context, aclass AssetsClass, asset asset.Currency) (res DepositMethodsResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, DepositMethodsResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// DepositAddresses gets a list of deposit addresses via the Kraken API.
// https://www.kraken.com/en-gb/help/api#deposit-methods
func (f *Funding) DepositAddresses(ctx context.Context, aclass AssetsClass, asset asset.Currency, method string, new bool) (res DepositAddressesResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"method": {method},
"new": {"false"},
}
if new {
body.Set("new", "true")
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, DepositAddressesResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// DepositStatus gets the status of recent deposits via the Kraken api.
// https://www.kraken.com/en-gb/help/api#deposit-methods
func (f *Funding) DepositStatus(ctx context.Context, aclass AssetsClass, asset asset.Currency, method string) (res *DepositStatusResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"method": {method},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, DepositStatusResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// WithdrawInfo gets withdrawal information via the Kraken api.
// https://www.kraken.com/en-gb/help/api#get-withdrawal-info
func (f *Funding) WithdrawInfo(ctx context.Context, aclass AssetsClass, asset asset.Currency, key string, amount float64) (res *WithdrawInfoResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"key": {key},
"amount": {strconv.FormatFloat(amount, 'f', 4, 64)},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, WithdrawInfoResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// Withdraw withdraws funds via the Kraken api.
// https://www.kraken.com/en-gb/help/api#withdraw-funds
func (f *Funding) Withdraw(ctx context.Context, aclass AssetsClass, asset asset.Currency, key string, amount float64) (res *WithdrawResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"key": {key},
"amount": {strconv.FormatFloat(amount, 'f', 4, 64)},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, WithdrawResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// WithdrawStatus gets status of recent withdrawals via the Kraken api.
// https://www.kraken.com/en-gb/help/api#withdraw-status
func (f *Funding) WithdrawStatus(ctx context.Context, aclass AssetsClass, asset asset.Currency, method string) (res WithdrawStatusResponse, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"method": {method},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, WithdrawStatusResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}
// WithdrawCancel requests withdrawal cancellation via the Kraken api.
// https://www.kraken.com/en-gb/help/api#withdraw-cancel
func (f *Funding) WithdrawCancel(ctx context.Context, aclass AssetsClass, asset asset.Currency, refID string) (res bool, err error) {
body := url.Values{
"aclass": {string(aclass)},
"asset": {asset.String()},
"refid": {refID},
}
req, err := f.Client.DialWithAuth(ctx, http.MethodPost, WithdrawCancelResource, body)
if err != nil {
return
}
krakenResp, err := f.Client.Call(req)
if err != nil {
return
}
err = krakenResp.ExtractResult(&res)
return
}