From 58c0616a46c19f9618da67f010b88dc0a83cf268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Rasc=C3=A3o?= Date: Mon, 17 Jan 2022 00:18:34 +0000 Subject: [PATCH] binance_cfutures: TimeOnForce is an optional order submission field (#867) Do not add it to the request unless filled out as the API will deny the request otherwise. --- exchanges/binance/binance_cfutures.go | 4 +++- exchanges/binance/binance_test.go | 2 +- exchanges/binance/binance_wrapper.go | 10 ++++++++-- exchanges/binance/cfutures_types.go | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/exchanges/binance/binance_cfutures.go b/exchanges/binance/binance_cfutures.go index 32c720b9..a0f47406 100644 --- a/exchanges/binance/binance_cfutures.go +++ b/exchanges/binance/binance_cfutures.go @@ -1000,7 +1000,9 @@ func (b *Binance) FuturesNewOrder(ctx context.Context, x *FuturesNewOrderRequest params.Set("positionSide", x.PositionSide) } params.Set("type", x.OrderType) - params.Set("timeInForce", x.TimeInForce) + if string(x.TimeInForce) != "" { + params.Set("timeInForce", string(x.TimeInForce)) + } if x.ReduceOnly { params.Set("reduceOnly", "true") } diff --git a/exchanges/binance/binance_test.go b/exchanges/binance/binance_test.go index af70bf57..a1fd153b 100644 --- a/exchanges/binance/binance_test.go +++ b/exchanges/binance/binance_test.go @@ -923,7 +923,7 @@ func TestFuturesNewOrder(t *testing.T) { Symbol: currency.NewPairWithDelimiter("BTCUSD", "PERP", "_"), Side: "BUY", OrderType: "LIMIT", - TimeInForce: "GTC", + TimeInForce: BinanceRequestParamsTimeGTC, Quantity: 1, Price: 1, }, diff --git a/exchanges/binance/binance_wrapper.go b/exchanges/binance/binance_wrapper.go index daa0820c..e4f089d9 100644 --- a/exchanges/binance/binance_wrapper.go +++ b/exchanges/binance/binance_wrapper.go @@ -956,10 +956,15 @@ func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi return submitOrderResponse, fmt.Errorf("invalid side") } - var oType string + var ( + oType string + timeInForce RequestParamsTimeForceType + ) + switch s.Type { case order.Limit: oType = cfuturesLimit + timeInForce = BinanceRequestParamsTimeGTC case order.Market: oType = cfuturesMarket case order.Stop: @@ -975,13 +980,14 @@ func (b *Binance) SubmitOrder(ctx context.Context, s *order.Submit) (order.Submi default: return submitOrderResponse, errors.New("invalid type, check api docs for updates") } + o, err := b.FuturesNewOrder( ctx, &FuturesNewOrderRequest{ Symbol: s.Pair, Side: reqSide, OrderType: oType, - TimeInForce: "GTC", + TimeInForce: timeInForce, NewClientOrderID: s.ClientOrderID, Quantity: s.Amount, Price: s.Price, diff --git a/exchanges/binance/cfutures_types.go b/exchanges/binance/cfutures_types.go index 36305835..dfde7ca5 100644 --- a/exchanges/binance/cfutures_types.go +++ b/exchanges/binance/cfutures_types.go @@ -212,7 +212,7 @@ type FuturesNewOrderRequest struct { Side string PositionSide string OrderType string - TimeInForce string + TimeInForce RequestParamsTimeForceType NewClientOrderID string ClosePosition string WorkingType string