-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts.go
152 lines (115 loc) · 4.11 KB
/
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
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
package tasty
import (
"fmt"
"net/http"
)
// Get the accounts for the authenticated client.
func (c *Client) GetMyAccounts() ([]Account, *http.Response, error) {
path := "/customers/me/accounts"
type accountResponse struct {
Data struct {
Items []struct {
Account Account `json:"account"`
} `json:"items"`
} `json:"data"`
}
accountsRes := new(accountResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, accountsRes)
if err != nil {
return []Account{}, resp, err
}
var accounts []Account
for _, acct := range accountsRes.Data.Items {
accounts = append(accounts, acct.Account)
}
return accounts, resp, nil
}
// Returns current trading status for an account.
func (c *Client) GetAccountTradingStatus(accountNumber string) (AccountTradingStatus, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/trading-status", accountNumber)
type tradingStatusRes struct {
AccountTradingStatus AccountTradingStatus `json:"data"`
}
accountsRes := new(tradingStatusRes)
resp, err := c.request(http.MethodGet, path, nil, nil, accountsRes)
if err != nil {
return AccountTradingStatus{}, resp, err
}
return accountsRes.AccountTradingStatus, resp, nil
}
// Returns the current balance values for an account.
func (c *Client) GetAccountBalances(accountNumber string) (AccountBalance, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/balances", accountNumber)
type accountBalanceRes struct {
AccountBalance AccountBalance `json:"data"`
}
accountsRes := new(accountBalanceRes)
resp, err := c.request(http.MethodGet, path, nil, nil, accountsRes)
if err != nil {
return AccountBalance{}, resp, err
}
return accountsRes.AccountBalance, resp, nil
}
// Returns a list of the account's positions.
// Can be filtered by symbol, underlying_symbol.
func (c *Client) GetAccountPositions(accountNumber string, query AccountPositionQuery) ([]AccountPosition, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/positions", accountNumber)
type accountResponse struct {
Data struct {
AccountPositions []AccountPosition `json:"items"`
} `json:"data"`
}
accountsRes := new(accountResponse)
resp, err := c.request(http.MethodGet, path, query, nil, accountsRes)
if err != nil {
return []AccountPosition{}, resp, err
}
return accountsRes.Data.AccountPositions, resp, nil
}
// Returns most recent snapshot and current balance for an account.
func (c *Client) GetAccountBalanceSnapshots(accountNumber string, query AccountBalanceSnapshotsQuery) ([]AccountBalanceSnapshots, *http.Response, error) {
// Default to EOD
if query.TimeOfDay == "" {
query.TimeOfDay = EndOfDay
}
path := fmt.Sprintf("/accounts/%s/balance-snapshots", accountNumber)
type accountResponse struct {
Data struct {
AccountBalanceSnapshots []AccountBalanceSnapshots `json:"items"`
} `json:"data"`
}
accountsRes := new(accountResponse)
resp, err := c.request(http.MethodGet, path, query, nil, accountsRes)
if err != nil {
return []AccountBalanceSnapshots{}, resp, err
}
return accountsRes.Data.AccountBalanceSnapshots, resp, nil
}
// Returns a list of account net liquidating value snapshots.
func (c *Client) GetAccountNetLiqHistory(accountNumber string, query HistoricLiquidityQuery) ([]NetLiqOHLC, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/net-liq/history", accountNumber)
type accountResponse struct {
Data struct {
HistoricLiquidity []NetLiqOHLC `json:"items"`
} `json:"data"`
}
accountsRes := new(accountResponse)
resp, err := c.request(http.MethodGet, path, query, nil, accountsRes)
if err != nil {
return []NetLiqOHLC{}, resp, err
}
return accountsRes.Data.HistoricLiquidity, resp, nil
}
// Get the position limit.
func (c *Client) GetAccountPositionLimit(accountNumber string) (PositionLimit, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/position-limit", accountNumber)
type accountResponse struct {
PositionLimit PositionLimit `json:"data"`
}
accountsRes := new(accountResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, accountsRes)
if err != nil {
return PositionLimit{}, resp, err
}
return accountsRes.PositionLimit, resp, nil
}