From abda9ae015fcf4e61bd4444e9bb697caf6567406 Mon Sep 17 00:00:00 2001 From: Geoff Catlin Date: Tue, 25 Jun 2024 13:51:09 -0400 Subject: [PATCH 1/2] Add missing AccountActivity fields: Status, OrderID, OrderStatus --- alpaca/entities.go | 3 +++ alpaca/entities_easyjson.go | 21 +++++++++++++++++++++ alpaca/rest_test.go | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/alpaca/entities.go b/alpaca/entities.go index 557e523..d94cfc8 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -186,6 +186,9 @@ type AccountActivity struct { NetAmount decimal.Decimal `json:"net_amount"` Description string `json:"description"` PerShareAmount decimal.Decimal `json:"per_share_amount"` + OrderID string `json:"order_id"` + OrderStatus string `json:"order_status"` + Status string `json:"status"` } //easyjson:json diff --git a/alpaca/entities_easyjson.go b/alpaca/entities_easyjson.go index 5087d25..6123a11 100644 --- a/alpaca/entities_easyjson.go +++ b/alpaca/entities_easyjson.go @@ -3017,6 +3017,12 @@ func easyjson3e8ab7adDecodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(in *jlexe if data := in.Raw(); in.Ok() { in.AddError((out.PerShareAmount).UnmarshalJSON(data)) } + case "order_id": + out.OrderID = string(in.String()) + case "order_status": + out.OrderStatus = string(in.String()) + case "status": + out.Status = string(in.String()) default: in.SkipRecursive() } @@ -3101,6 +3107,21 @@ func easyjson3e8ab7adEncodeGithubComAlpacahqAlpacaTradeApiGoV3Alpaca23(out *jwri out.RawString(prefix) out.Raw((in.PerShareAmount).MarshalJSON()) } + { + const prefix string = ",\"order_id\":" + out.RawString(prefix) + out.String(string(in.OrderID)) + } + { + const prefix string = ",\"order_status\":" + out.RawString(prefix) + out.String(string(in.OrderStatus)) + } + { + const prefix string = ",\"status\":" + out.RawString(prefix) + out.String(string(in.Status)) + } out.RawByte('}') } diff --git a/alpaca/rest_test.go b/alpaca/rest_test.go index db57459..99188d9 100644 --- a/alpaca/rest_test.go +++ b/alpaca/rest_test.go @@ -941,6 +941,7 @@ func TestGetAccountActivities(t *testing.T) { "symbol": "T", "qty": "2", "per_share_amount": "0.51", + "status": "executed", }, { "activity_type": "DIV", @@ -950,6 +951,21 @@ func TestGetAccountActivities(t *testing.T) { "symbol": "AAPL", "qty": "2", "per_share_amount": "100", + "status": "executed", + }, + { + "activity_type": "FILL", + "id": "20240624093004214::18a82342-245e-4e8a-9703-87ae38d9b629", + "transaction_time": "2024-06-24T13:30:04.214535Z", + "type": "partial_fill", + "price": "3.8", + "qty": "643", + "side": "sell", + "symbol": "AAPL", + "leaves_qty": "1457", + "order_id": "c0e497c2-a547-48cd-85dc-0f1f0ed1b26c", + "cum_qty": "643", + "order_status": "partially_filled", }, } return &http.Response{ @@ -958,10 +974,10 @@ func TestGetAccountActivities(t *testing.T) { } activities, err := c.GetAccountActivities(GetAccountActivitiesRequest{ - ActivityTypes: []string{"DIV"}, + ActivityTypes: []string{"DIV", "FILL"}, }) assert.NoError(t, err) - assert.Len(t, activities, 2) + assert.Len(t, activities, 3) activity1 := activities[0] assert.Equal(t, civil.Date{Year: 2019, Month: 8, Day: 1}, activity1.Date) assert.Equal(t, "DIV", activity1.ActivityType) @@ -970,6 +986,7 @@ func TestGetAccountActivities(t *testing.T) { assert.Equal(t, "T", activity1.Symbol) assert.Equal(t, decimal.NewFromInt(2), activity1.Qty) assert.Equal(t, decimal.NewFromFloat32(0.51), activity1.PerShareAmount) + assert.Equal(t, "executed", activity1.Status) activity2 := activities[1] assert.Equal(t, civil.Date{Year: 2019, Month: 8, Day: 1}, activity2.Date) assert.Equal(t, "DIV", activity2.ActivityType) @@ -978,6 +995,20 @@ func TestGetAccountActivities(t *testing.T) { assert.Equal(t, "AAPL", activity2.Symbol) assert.Equal(t, decimal.NewFromInt(2), activity2.Qty) assert.Equal(t, decimal.NewFromInt(100), activity2.PerShareAmount) + assert.Equal(t, "executed", activity2.Status) + activity3 := activities[2] + assert.Equal(t, "FILL", activity3.ActivityType) + assert.Equal(t, "20240624093004214::18a82342-245e-4e8a-9703-87ae38d9b629", activity3.ID) + assert.Equal(t, "2024-06-24T13:30:04.214535Z", activity3.TransactionTime.Format("2006-01-02T15:04:05.999999Z")) + assert.Equal(t, "partial_fill", activity3.Type) + assert.True(t, decimal.NewFromFloat32(3.8).Equal(activity3.Price)) + assert.Equal(t, decimal.NewFromInt(643), activity3.Qty) + assert.Equal(t, "sell", activity3.Side) + assert.Equal(t, "AAPL", activity3.Symbol) + assert.Equal(t, decimal.NewFromInt(1457), activity3.LeavesQty) + assert.Equal(t, "c0e497c2-a547-48cd-85dc-0f1f0ed1b26c", activity3.OrderID) + assert.Equal(t, decimal.NewFromInt(643), activity3.CumQty) + assert.Equal(t, "partially_filled", activity3.OrderStatus) // error was returned c.do = func(c *Client, req *http.Request) (*http.Response, error) { @@ -1009,6 +1040,7 @@ func TestGetAccountActivities(t *testing.T) { "symbol": "T", "qty": "2", "per_share_amount": "0.51", + "status": "executed", }, } return &http.Response{ From ac3f677ee9935522d95a0b81df7dd01380cc7987 Mon Sep 17 00:00:00 2001 From: Geoff Catlin Date: Tue, 25 Jun 2024 14:25:07 -0400 Subject: [PATCH 2/2] Add GetAccountActivitiesRequest fields: PageToken, Category --- alpaca/rest.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/alpaca/rest.go b/alpaca/rest.go index 3e8fa52..f8eb5b1 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -187,6 +187,8 @@ type GetAccountActivitiesRequest struct { After time.Time `json:"after"` Direction string `json:"direction"` PageSize int `json:"page_size"` + PageToken string `json:"page_token"` + Category string `json:"category"` } // GetAccountActivities returns the account activities. @@ -215,6 +217,12 @@ func (c *Client) GetAccountActivities(req GetAccountActivitiesRequest) ([]Accoun if req.PageSize != 0 { q.Set("page_size", strconv.Itoa(req.PageSize)) } + if req.PageToken != "" { + q.Set("page_token", req.PageToken) + } + if req.Category != "" { + q.Set("category", req.Category) + } u.RawQuery = q.Encode() resp, err := c.get(u)