-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.go
132 lines (112 loc) · 3.85 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
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
package allyinvest
import (
"fmt"
"net/url"
)
// GetAccountHodingsInput are the required or optional parameters
// to GetAccountHoldings.
type GetAccountHoldingsInput struct {
// REQUIRED: The account ID for which you are requesting holdings.
AccountID *string `validate:"required"`
}
// GetAccountHoldings returns the holdings for the specified account.
func (a *api) GetAccountHoldings(input GetAccountHoldingsInput) (GetAccountHoldingsOutput, error) {
output := GetAccountHoldingsOutput{}
err := validate(input)
if err != nil {
return output, err
}
route := fmt.Sprintf("/accounts/%s/holdings", *input.AccountID)
err = a.httpGet(route, url.Values{}, &output)
return output, err
}
// GetAccountHistoryInput are the required or optional parameters
// to GetAccountHistory.
type GetAccountHistoryInput struct {
// REQUIRED: The account ID for which you are requesting history.
AccountID *string `validate:"required"`
// OPTIONAL: Date range of transacations. Valid values:
//
// AccountHistoryDateRangeAll: "all"
// AccountHistoryDateRangeToday: "today"
// AccountHistoryDateRangeCurrentWeek: "current_week"
// AccountHistoryDateRangeCurrentMonth: "current_month"
// AccountHistoryDateRangeLastMonth: "last_month"
Range *AccountHistoryDateRange
// OPTIONAL: The kind of transactions to show. Valid values:
//
// AccountHistoryTransactionAll: "all"
// AccountHistoryTransactionBookkeeping: "bookkeeping"
// AccountHistoryTransactionTrade: "trade"
Transactions *AccountHistoryTransaction
}
// Encode encodes g to a query string.
func (g GetAccountHistoryInput) Encode() string {
u := url.Values{}
if g.Range != nil {
u.Add("range", string(*g.Range))
}
if g.Transactions != nil {
u.Add("transactions", string(*g.Transactions))
}
return u.Encode()
}
// GetAccountHistory returns the history for the specified account.
func (a *api) GetAccountHistory(input GetAccountHistoryInput) (GetAccountHistoryOutput, error) {
output := GetAccountHistoryOutput{}
err := validate(input)
if err != nil {
return output, err
}
route := fmt.Sprintf("/accounts/%s/history", *input.AccountID)
err = a.httpGet(route, input, &output)
return output, err
}
// GetAccountBalancesInput are the required or optional parameters
// to GetAccountBalances.
type GetAccountBalancesInput struct {
// REQUIRED: The account ID for which you are requesting balances.
AccountID *string `validate:"required"`
}
// GetAccountBalances returns the balances for the specified account.
func (a *api) GetAccountBalances(input GetAccountBalancesInput) (GetAccountBalancesOutput, error) {
output := GetAccountBalancesOutput{}
err := validate(input)
if err != nil {
return output, err
}
route := fmt.Sprintf("/accounts/%s/balances", *input.AccountID)
err = a.httpGet(route, url.Values{}, &output)
return output, err
}
// GetAccountInput are the required or optional parameters
// to GetAccount.
type GetAccountInput struct {
// REQUIRED: The account ID for which you are requesting the summary.
AccountID *string `validate:"required"`
}
// GetAccount returns the summary for the specified account.
func (a *api) GetAccount(input GetAccountInput) (GetAccountOutput, error) {
output := GetAccountOutput{}
err := validate(input)
if err != nil {
return output, err
}
route := fmt.Sprintf("/accounts/%s", *input.AccountID)
err = a.httpGet(route, url.Values{}, &output)
return output, err
}
// GetAccountsBalances returns the balance summary for each account.
func (a *api) GetAccountsBalances() (GetAccountsBalancesOutput, error) {
output := GetAccountsBalancesOutput{}
route := "/accounts/balances"
err := a.httpGet(route, url.Values{}, &output)
return output, err
}
// GetAccounts lists all accounts associated with a user.
func (a *api) GetAccounts() (GetAccountsOutput, error) {
output := GetAccountsOutput{}
route := "/accounts"
err := a.httpGet(route, url.Values{}, &output)
return output, err
}