From 021aa5542ca5c3e8231d47d30313b66db1572f3f Mon Sep 17 00:00:00 2001 From: lychiyu Date: Sun, 1 Sep 2024 20:38:14 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20=E6=96=B0=E5=A2=9E=E5=90=88=E7=BA=A6?= =?UTF-8?q?=E6=AD=A2=E7=9B=88=E8=AE=A2=E5=8D=95=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/exchange/binance/convert_futures.go | 8 +++++++- pkg/exchange/binance/futures.go | 5 +++-- pkg/types/order.go | 18 ++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/exchange/binance/convert_futures.go b/pkg/exchange/binance/convert_futures.go index 2f2f547..52ec90a 100644 --- a/pkg/exchange/binance/convert_futures.go +++ b/pkg/exchange/binance/convert_futures.go @@ -93,6 +93,12 @@ func toLocalFuturesOrderType(orderType types.OrderType) (futures.OrderType, erro // case types.OrderTypeStopMarket: // return futures.OrderTypeStopLoss, nil //TODO + case types.OrderTypeStopMarket: + return futures.OrderTypeStopMarket, nil //TODO + + case types.OrderTypeTakeProfitMarket: + return futures.OrderTypeTakeProfitMarket, nil + case types.OrderTypeMarket: return futures.OrderTypeMarket, nil } @@ -211,7 +217,7 @@ func toGlobalFuturesOrderType(orderType futures.OrderType) types.OrderType { return types.OrderTypeStopLimit case futures.OrderTypeTakeProfitMarket: - return types.OrderTypeStopMarket + return types.OrderTypeTakeProfitMarket case futures.OrderTypeStopMarket: return types.OrderTypeStopMarket diff --git a/pkg/exchange/binance/futures.go b/pkg/exchange/binance/futures.go index 40554f7..2614d03 100644 --- a/pkg/exchange/binance/futures.go +++ b/pkg/exchange/binance/futures.go @@ -139,7 +139,8 @@ func (e *Exchange) submitFuturesOrder(ctx context.Context, order types.SubmitOrd req := e.futuresClient.NewCreateOrderService(). Symbol(order.Symbol). Type(orderType). - Side(futures.SideType(order.Side)) + Side(futures.SideType(order.Side)). + PositionSide(futures.PositionSideType(order.PositionSide)) if order.ReduceOnly { req.ReduceOnly(order.ReduceOnly) @@ -178,7 +179,7 @@ func (e *Exchange) submitFuturesOrder(ctx context.Context, order types.SubmitOrd // set stop price switch order.Type { - case types.OrderTypeStopLimit, types.OrderTypeStopMarket: + case types.OrderTypeStopLimit, types.OrderTypeStopMarket, types.OrderTypeTakeProfitMarket: if order.Market.Symbol != "" { req.StopPrice(order.Market.FormatPrice(order.StopPrice)) } else { diff --git a/pkg/types/order.go b/pkg/types/order.go index 253c061..d9c078e 100644 --- a/pkg/types/order.go +++ b/pkg/types/order.go @@ -79,11 +79,12 @@ func (t *MarginOrderSideEffectType) UnmarshalJSON(data []byte) error { type OrderType string const ( - OrderTypeLimit OrderType = "LIMIT" - OrderTypeLimitMaker OrderType = "LIMIT_MAKER" - OrderTypeMarket OrderType = "MARKET" - OrderTypeStopLimit OrderType = "STOP_LIMIT" - OrderTypeStopMarket OrderType = "STOP_MARKET" + OrderTypeLimit OrderType = "LIMIT" + OrderTypeLimitMaker OrderType = "LIMIT_MAKER" + OrderTypeMarket OrderType = "MARKET" + OrderTypeStopLimit OrderType = "STOP_LIMIT" + OrderTypeStopMarket OrderType = "STOP_MARKET" + OrderTypeTakeProfitMarket OrderType = "TAKE_PROFIT_MARKET" ) /* @@ -130,9 +131,10 @@ func (o OrderStatus) Closed() bool { type SubmitOrder struct { ClientOrderID string `json:"clientOrderID,omitempty" db:"client_order_id"` - Symbol string `json:"symbol" db:"symbol"` - Side SideType `json:"side" db:"side"` - Type OrderType `json:"orderType" db:"order_type"` + Symbol string `json:"symbol" db:"symbol"` + Side SideType `json:"side" db:"side"` + PositionSide PositionSideType `json:"positionSide" db:"positionSide"` + Type OrderType `json:"orderType" db:"order_type"` Quantity fixedpoint.Value `json:"quantity" db:"quantity"` Price fixedpoint.Value `json:"price" db:"price"`