diff --git a/alpaca/entities.go b/alpaca/entities.go index 0577390..cd1d8f5 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -181,6 +181,13 @@ type AccountActvity struct { PerShareAmount decimal.Decimal `json:"per_share_amount"` } +type PortfolioHistory struct { + Arrays []interface{} `json:"arrays"` + Attributes []map[string]string `json:"attributes"` + Timeframe RangeFreq `json:"timeframe"` + BaseValue float64 `json:"base_value"` +} + type PlaceOrderRequest struct { AccountID string `json:"-"` AssetKey *string `json:"symbol"` @@ -288,6 +295,27 @@ const ( All TradeConfirmEmail = "all" ) +type HistoryPeriod string + +const ( + Month1 HistoryPeriod = "1M" + Month3 HistoryPeriod = "3M" + Month6 HistoryPeriod = "6M" + Year HistoryPeriod = "1A" + AllHistory HistoryPeriod = "all" + Intraday HistoryPeriod = "intraday" +) + +type RangeFreq string + +const ( + Min1 RangeFreq = "1Min" + Min5 RangeFreq = "5Min" + Min15 RangeFreq = "15Min" + Hour1 RangeFreq = "1H" + Day1 RangeFreq = "1D" +) + // stream // ClientMsg is the standard message sent by clients of the stream interface diff --git a/alpaca/rest.go b/alpaca/rest.go index f428ce4..38bbf53 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -193,6 +193,32 @@ func (c *Client) GetAccountActivities(activityType *string, opts *AccountActivit return activities, nil } +func (c *Client) GetPortfolioHistory(startDate, endDate *time.Time, period *HistoryPeriod, timeframe *RangeFreq, extended bool) (*PortfolioHistory, error) { + var u *url.URL + var err error + u, err = url.Parse(fmt.Sprintf("%s/%s/account/portfolio/history", base, apiVersion)) + if err != nil { + return nil, err + } + + q := u.Query() + if startDate != nil { + q.Set("start_date", startDate.Format(time.RFC3339)) + } + if endDate != nil { + q.Set("end_date", endDate.Format(time.RFC3339)) + } + if period != nil { + q.Set("period", string(*period)) + } + if timeframe != nil { + q.Set("period", string(*timeframe)) + } + q.Set("extended", strconv.FormatBool(extended)) + + return &PortfolioHistory{}, nil +} + // ListPositions lists the account's open positions. func (c *Client) ListPositions() ([]Position, error) { u, err := url.Parse(fmt.Sprintf("%s/%s/positions", base, apiVersion)) @@ -588,6 +614,10 @@ func GetAccountActivities(activityType *string, opts *AccountActivitiesRequest) return DefaultClient.GetAccountActivities(activityType, opts) } +func GetPortfolioHistory(startDate, endDate *time.Time, period *HistoryPeriod, timeframe *RangeFreq, extended bool) (*PortfolioHistory, error) { + return DefaultClient.GetPortfolioHistory(startDate, endDate, period, timeframe, extended) +} + // ListPositions lists the account's open positions // using the default Alpaca client. func ListPositions() ([]Position, error) {