-
-
Notifications
You must be signed in to change notification settings - Fork 296
/
rest_wallet_request.go
62 lines (50 loc) · 1.3 KB
/
rest_wallet_request.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
package ftx
import (
"context"
"encoding/json"
"fmt"
"strconv"
"time"
)
type walletRequest struct {
*restRequest
}
func (r *walletRequest) DepositHistory(ctx context.Context, since time.Time, until time.Time, limit int) (depositHistoryResponse, error) {
q := make(map[string]string)
if limit > 0 {
q["limit"] = strconv.Itoa(limit)
}
if since != (time.Time{}) {
q["start_time"] = strconv.FormatInt(since.Unix(), 10)
}
if until != (time.Time{}) {
q["end_time"] = strconv.FormatInt(until.Unix(), 10)
}
resp, err := r.
Method("GET").
ReferenceURL("api/wallet/deposits").
Query(q).
DoAuthenticatedRequest(ctx)
if err != nil {
return depositHistoryResponse{}, err
}
var d depositHistoryResponse
if err := json.Unmarshal(resp.Body, &d); err != nil {
return depositHistoryResponse{}, fmt.Errorf("failed to unmarshal deposit history response body to json: %w", err)
}
return d, nil
}
func (r *walletRequest) Balances(ctx context.Context) (balances, error) {
resp, err := r.
Method("GET").
ReferenceURL("api/wallet/balances").
DoAuthenticatedRequest(ctx)
if err != nil {
return balances{}, err
}
var b balances
if err := json.Unmarshal(resp.Body, &b); err != nil {
return balances{}, fmt.Errorf("failed to unmarshal balance response body to json: %w", err)
}
return b, nil
}