From 8642da98f386b699a9abca62935630e77e4775e2 Mon Sep 17 00:00:00 2001 From: Ankit Sridhar <36269838+ankitsridhar16@users.noreply.github.com> Date: Wed, 10 Jul 2024 01:20:16 +0530 Subject: [PATCH] Add position intent to PlaceOrderRequest (#294) * chore: added position intent to entities.go * chore: added position intent to PlaceOrderRequest type * chore: moved side constants below type declaration --- alpaca/entities.go | 9 +++++++++ alpaca/rest.go | 31 ++++++++++++++++--------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/alpaca/entities.go b/alpaca/entities.go index d94cfc8..9c367a4 100644 --- a/alpaca/entities.go +++ b/alpaca/entities.go @@ -210,6 +210,15 @@ const ( Sell Side = "sell" ) +type PositionIntent string + +const ( + BuyToOpen PositionIntent = "buy_to_open" + BuyToClose PositionIntent = "buy_to_close" + SellToOpen PositionIntent = "sell_to_open" + SellToClose PositionIntent = "sell_to_close" +) + type OrderType string const ( diff --git a/alpaca/rest.go b/alpaca/rest.go index f8eb5b1..00a2a61 100644 --- a/alpaca/rest.go +++ b/alpaca/rest.go @@ -518,21 +518,22 @@ func (c *Client) GetOrders(req GetOrdersRequest) ([]Order, error) { } type PlaceOrderRequest struct { - Symbol string `json:"symbol"` - Qty *decimal.Decimal `json:"qty"` - Notional *decimal.Decimal `json:"notional"` - Side Side `json:"side"` - Type OrderType `json:"type"` - TimeInForce TimeInForce `json:"time_in_force"` - LimitPrice *decimal.Decimal `json:"limit_price"` - ExtendedHours bool `json:"extended_hours"` - StopPrice *decimal.Decimal `json:"stop_price"` - ClientOrderID string `json:"client_order_id"` - OrderClass OrderClass `json:"order_class"` - TakeProfit *TakeProfit `json:"take_profit"` - StopLoss *StopLoss `json:"stop_loss"` - TrailPrice *decimal.Decimal `json:"trail_price"` - TrailPercent *decimal.Decimal `json:"trail_percent"` + Symbol string `json:"symbol"` + Qty *decimal.Decimal `json:"qty"` + Notional *decimal.Decimal `json:"notional"` + Side Side `json:"side"` + Type OrderType `json:"type"` + TimeInForce TimeInForce `json:"time_in_force"` + LimitPrice *decimal.Decimal `json:"limit_price"` + ExtendedHours bool `json:"extended_hours"` + StopPrice *decimal.Decimal `json:"stop_price"` + ClientOrderID string `json:"client_order_id"` + OrderClass OrderClass `json:"order_class"` + TakeProfit *TakeProfit `json:"take_profit"` + StopLoss *StopLoss `json:"stop_loss"` + TrailPrice *decimal.Decimal `json:"trail_price"` + TrailPercent *decimal.Decimal `json:"trail_percent"` + PositionIntent PositionIntent `json:"position_intent"` } type TakeProfit struct {