-
Notifications
You must be signed in to change notification settings - Fork 145
/
account.go
86 lines (69 loc) · 1.92 KB
/
account.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
package coinbasepro
import (
"fmt"
)
type Account struct {
ID string `json:"id"`
Balance string `json:"balance"`
Hold string `json:"hold"`
Available string `json:"available"`
Currency string `json:"currency"`
}
// Ledger
type LedgerEntry struct {
ID string `json:"id,number"`
CreatedAt Time `json:"created_at,string"`
Amount string `json:"amount"`
Balance string `json:"balance"`
Type string `json:"type"`
Details LedgerDetails `json:"details"`
}
type LedgerDetails struct {
OrderID string `json:"order_id"`
TradeID string `json:"trade_id"`
ProductID string `json:"product_id"`
}
type GetAccountLedgerParams struct {
Pagination PaginationParams
}
// Holds
type Hold struct {
AccountID string `json:"account_id"`
CreatedAt Time `json:"created_at,string"`
UpdatedAt Time `json:"updated_at,string"`
Amount string `json:"amount"`
Type string `json:"type"`
Ref string `json:"ref"`
}
type ListHoldsParams struct {
Pagination PaginationParams
}
// Client Funcs
func (c *Client) GetAccounts() ([]Account, error) {
var accounts []Account
_, err := c.Request("GET", "/accounts", nil, &accounts)
return accounts, err
}
func (c *Client) GetAccount(id string) (Account, error) {
account := Account{}
url := fmt.Sprintf("/accounts/%s", id)
_, err := c.Request("GET", url, nil, &account)
return account, err
}
func (c *Client) ListAccountLedger(id string,
p ...GetAccountLedgerParams) *Cursor {
paginationParams := PaginationParams{}
if len(p) > 0 {
paginationParams = p[0].Pagination
}
return NewCursor(c, "GET", fmt.Sprintf("/accounts/%s/ledger", id),
&paginationParams)
}
func (c *Client) ListHolds(id string, p ...ListHoldsParams) *Cursor {
paginationParams := PaginationParams{}
if len(p) > 0 {
paginationParams = p[0].Pagination
}
return NewCursor(c, "GET", fmt.Sprintf("/accounts/%s/holds", id),
&paginationParams)
}