-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustodial_accounts.go
121 lines (103 loc) · 4.57 KB
/
custodial_accounts.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
package rize
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
"github.com/google/go-querystring/query"
)
// Handles all CustodialAccount operations
type custodialAccountService service
// CustodialAccount data type
type CustodialAccount struct {
UID string `json:"uid,omitempty"`
ExternalUID string `json:"external_uid,omitempty"`
CustomerUID string `json:"customer_uid,omitempty"`
PoolUID string `json:"pool_uid,omitempty"`
Type string `json:"type,omitempty"`
Liability bool `json:"liability,omitempty"`
Name string `json:"name,omitempty"`
PrimaryAccount bool `json:"primary_account,omitempty"`
Status string `json:"status,omitempty"`
AccountErrors []*CustodialAccountError `json:"account_errors,omitempty"`
NetUSDBalance string `json:"net_usd_balance,omitempty"`
NetUSDPendingBalance string `json:"net_usd_pending_balance,omitempty"`
NetUSDAvailableBalance string `json:"net_usd_available_balance,omitempty"`
AssetBalances []*CustodialAccountAssetBalance `json:"asset_balances,omitempty"`
AccountNumber string `json:"account_number,omitempty"`
AccountNumberMasked string `json:"account_number_masked,omitempty"`
RoutingNumber string `json:"routing_number,omitempty"`
OpenedAt time.Time `json:"opened_at,omitempty"`
ClosedAt time.Time `json:"closed_at,omitempty"`
}
// CustodialAccountError provides errors info related to this account
type CustodialAccountError struct {
ErrorCode string `json:"error_code,omitempty"`
ErrorName string `json:"error_name,omitempty"`
ErrorDescription string `json:"error_description,omitempty"`
}
// CustodialAccountAssetBalance provides balance info for the various asset types held in this Custodial Account
type CustodialAccountAssetBalance struct {
AssetQuantity string `json:"asset_quantity,omitempty"`
AssetType string `json:"asset_type,omitempty"`
CurrentUSDValue string `json:"current_usd_value,omitempty"`
Debit bool `json:"debit,omitempty"`
}
// CustodialAccountListParams builds the query parameters used in querying Custodial Accounts
type CustodialAccountListParams struct {
CustomerUID string `url:"customer_uid,omitempty" json:"customer_uid,omitempty"`
ExternalUID string `url:"external_uid,omitempty" json:"external_uid,omitempty"`
Limit int `url:"limit,omitempty" json:"limit,omitempty"`
Offset int `url:"offset,omitempty" json:"offset,omitempty"`
Liability bool `url:"liability,omitempty" json:"liability,omitempty"`
Type string `url:"type,omitempty" json:"type,omitempty"`
}
// CustodialAccountListResponse is an API response containing a list of Custodial Accounts
type CustodialAccountListResponse struct {
ListResponse
Data []*CustodialAccount `json:"data"`
}
// List retrieves a list of Custodial Accounts filtered by the given parameters
func (c *custodialAccountService) List(ctx context.Context, params *CustodialAccountListParams) (*CustodialAccountListResponse, error) {
// Build CustodialAccountListParams into query string params
v, err := query.Values(params)
if err != nil {
return nil, err
}
res, err := c.client.doRequest(ctx, http.MethodGet, "custodial_accounts", v, nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
response := &CustodialAccountListResponse{}
if err = json.Unmarshal(body, response); err != nil {
return nil, err
}
return response, nil
}
// Get returns a single Custodial Account
func (c *custodialAccountService) Get(ctx context.Context, uid string) (*CustodialAccount, error) {
if uid == "" {
return nil, fmt.Errorf("UID is required")
}
res, err := c.client.doRequest(ctx, http.MethodGet, fmt.Sprintf("custodial_accounts/%s", uid), nil, nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
response := &CustodialAccount{}
if err = json.Unmarshal(body, response); err != nil {
return nil, err
}
return response, nil
}