From 954032ab7b6049418468b3a554ad3d7276383f1a Mon Sep 17 00:00:00 2001 From: ttt733 Date: Fri, 28 Feb 2020 09:59:25 -0600 Subject: [PATCH] Fix portfolio history format --- alpaca/entities.go | 10 ++++++---- alpaca/rest.go | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/alpaca/entities.go b/alpaca/entities.go index cd1d8f5..8496153 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -182,10 +182,12 @@ type AccountActvity struct { } type PortfolioHistory struct { - Arrays []interface{} `json:"arrays"` - Attributes []map[string]string `json:"attributes"` - Timeframe RangeFreq `json:"timeframe"` - BaseValue float64 `json:"base_value"` + BaseValue decimal.Decimal `json:"base_value"` + Equity []decimal.Decimal `json:"equity"` + ProfitLoss []decimal.Decimal `json:"profit_loss"` + ProfitLossPct []decimal.Decimal `json:"profit_loss_pct"` + Timeframe RangeFreq `json:"timeframe"` + Timestamp []int64 `json:"timestamp"` } type PlaceOrderRequest struct { diff --git a/alpaca/rest.go b/alpaca/rest.go index 38bbf53..13e9629 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -216,7 +216,17 @@ func (c *Client) GetPortfolioHistory(startDate, endDate *time.Time, period *Hist } q.Set("extended", strconv.FormatBool(extended)) - return &PortfolioHistory{}, nil + resp, err := c.get(u) + if err != nil { + return nil, err + } + + portfolioHistory := PortfolioHistory{} + if err = unmarshal(resp, &portfolioHistory); err != nil { + return nil, err + } + + return &portfolioHistory, nil } // ListPositions lists the account's open positions.