-
Notifications
You must be signed in to change notification settings - Fork 34
/
portfolios.go
51 lines (46 loc) · 2.61 KB
/
portfolios.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
package robinhood
import "context"
// Portfolio holds all information regarding the portfolio
type Portfolio struct {
Account string `json:"account"`
AdjustedEquityPreviousClose float64 `json:"adjusted_equity_previous_close,string"`
Equity float64 `json:"equity,string"`
EquityPreviousClose float64 `json:"equity_previous_close,string"`
ExcessMaintenance float64 `json:"excess_maintenance,string"`
ExcessMaintenanceWithUnclearedDeposits float64 `json:"excess_maintenance_with_uncleared_deposits,string"`
ExcessMargin float64 `json:"excess_margin,string"`
ExcessMarginWithUnclearedDeposits float64 `json:"excess_margin_with_uncleared_deposits,string"`
ExtendedHoursEquity float64 `json:"extended_hours_equity,string"`
ExtendedHoursMarketValue float64 `json:"extended_hours_market_value,string"`
LastCoreEquity float64 `json:"last_core_equity,string"`
LastCoreMarketValue float64 `json:"last_core_market_value,string"`
MarketValue float64 `json:"market_value,string"`
StartDate string `json:"start_date"`
UnwithdrawableDeposits float64 `json:"unwithdrawable_deposits,string"`
UnwithdrawableGrants float64 `json:"unwithdrawable_grants,string"`
URL string `json:"url"`
WithdrawableAmount float64 `json:"withdrawable_amount,string"`
}
// CryptoPortfolio returns all the portfolio associated with a client's account
type CryptoPortfolio struct {
AccountID string `json:"account_id"`
Equity float64 `json:"equity,string"`
ExtendedHoursEquity float64 `json:"extended_hours_equity,string"`
ExtendedHoursMarketValue float64 `json:"extended_hours_market_value,string"`
ID string `json:"id"`
MarketValue float64 `json:"market_value,string"`
}
// GetPortfolios returns all the portfolios associated with a client's
// credentials and accounts
func (c *Client) GetPortfolios(ctx context.Context) ([]Portfolio, error) {
var p struct{ Results []Portfolio }
err := c.GetAndDecode(ctx, EPPortfolios, &p)
return p.Results, err
}
// GetCryptoPortfolios returns crypto portfolio info
func (c *Client) GetCryptoPortfolios(ctx context.Context) (CryptoPortfolio, error) {
var p CryptoPortfolio
var portfolioURL = EPCryptoPortfolio + c.CryptoAccount.ID
err := c.GetAndDecode(ctx, portfolioURL, &p)
return p, err
}