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.
This commit is contained in:
Luis Rascão
2022-01-17 00:18:34 +00:00
committed by GitHub
parent 92047dac87
commit 58c0616a46
4 changed files with 13 additions and 5 deletions

View File

@@ -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")
}

View File

@@ -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,
},

View File

@@ -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,

View File

@@ -212,7 +212,7 @@ type FuturesNewOrderRequest struct {
Side string
PositionSide string
OrderType string
TimeInForce string
TimeInForce RequestParamsTimeForceType
NewClientOrderID string
ClosePosition string
WorkingType string