Code: -2022. ReduceOnly Order is rejected.

Hello. I have a mistake.
I using Futures Hedge Mode.

When I run the script for 1-5 coins, the script works perfect without errors and warnings. But if I launch more than 10-15 coins, then sometimes an error appears when closing a short position:
"Object: null prototype] {
Code: -2022,
msg: “Only the reduction order was rejected.”
}

There is also a feeling that this error is more common with certain coins.
Thanks for help to me

Part of my code.

let orders = [{
symbol: ${pair.pair},
positionSide: ‘LONG’,
side: ‘SELL’,
type: ‘MARKET’,
quantity: ${pair.amount}
},
{
symbol: ${pair.pair},
positionSide: ‘SHORT’,
side: ‘BUY’,
type: ‘MARKET’,
quantity: ${pair.amount}
}
]
console.info(await binance.futuresMultipleOrders(orders))

Let’s start. Opened two positions. All fine

     Pair: GTCUSDT

step 1 - LONG POSITION - CLOSE. All fine

[3:47: LONG STOPLOSS IS ACTIVATED.
------------------- CLOSE LONG -------------------
[
[Object: null prototype] {
orderId: 356839251,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘mx0n7ikwrUMLPMq8vxN6QA0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: true,
closePosition: false,
side: ‘SELL’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634690835506
}
]
------------------- COMPLETE -------------------

step 1-1 (WTF???) why is it trying to close position long again ??? This is an extra step, it is not in the code.

But the most surprising thing is that this error has no effect, because it is associated with the closure of a long position. Therefore, you can ignore it.

Nothing happens in binance either.

Move on.

[3:47: LONG STOPLOSS IS ACTIVATED.
------------------- CLOSE LONG -------------------
[
[Object: null prototype] {
code: -2022,
msg: ‘ReduceOnly Order is rejected.’
}
]
------------------- COMPLETE -------------------
(node: 8064) UnhandledPromiseRejectionWarning: Error: ESOCKETTIMEDOUT
at ClientRequest. (C: \ Users \ Administrator \ Desktop \ new Botk \ node_modules \ request \ request.js: 816: 19)
at Object.onceWrapper (events.js: 519: 28)
at ClientRequest.emit (events.js: 400: 28)
at TLSSocket.emitRequestTimeout (_http_client.js: 790: 9)
at Object.onceWrapper (events.js: 519: 28)
at TLSSocket.emit (events.js: 412: 35)
at TLSSocket.Socket._onTimeout (net.js: 495: 8)
at listOnTimeout (internal / timers.js: 557: 17)
at processTimers (internal / timers.js: 500: 7)
(node: 8064) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch (). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections = strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 168)

step 3 - all fine. We closing last opened position SHORT and re-open orders short + long

------------------- CLOSE SHORT -------------------
[
[Object: null prototype] {
orderId: 356846054,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘tEGpn16ZLUMMRvqQ4Cgvke0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: true,
closePosition: false,
side: ‘BUY’,
positionSide: ‘SHORT’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634690866860
}
]

First step CLOSE SHORT. All fine. Next Step opening new orders long + short. As well good.

[
[Object: null prototype] {
orderId: 356846195,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘z2EU16r78TWMmlebGRFgeS0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘BUY’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634690867648
},
[Object: null prototype] {
orderId: 356846196,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘xYlmrceAGHb2pbe7l00uLI1’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘SELL’,
positionSide: ‘SHORT’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634690867648
}
]

step 4 - If you forget about step 1-1, everything is still working.

[4:19: SHORT STOPLOSS IS ACTIVATED.
------------------- CLOSE SHORT -------------------
StopLossLong GTCUSDT OLD: 10.920364
StopLossLong GTCUSDT NEW: 10.920364
[
[Object: null prototype] {
orderId: 357138829,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘3NwwIA1jDEod5QPLogozWg0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: true,
closePosition: false,
side: ‘BUY’,
positionSide: ‘SHORT’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692792725
}
]

step 4-1 - as in the previous error, the script tries to close the position once again and we get 2022. But now the bot closes the short position and everything will not go on so sweetly.

[4:20: SHORT STOPLOSS IS ACTIVATED.
------------------- CLOSE SHORT -------------------
StopLossLong GTCUSDT OLD: 10.920364
StopLossLong GTCUSDT NEW: 10.920364
[
[Object: null prototype] {
code: -2022,
msg: ‘ReduceOnly Order is rejected.’
}
]

step 5 - let’s begin

[4:21: LONG STOPLOSS IS ACTIVATED.
------------------- GTCUSDT CLOSE LONG -------------------

step 5-1 - every step same on binance. Was check every orderID.
ALL FINE

[
[Object: null prototype] {
orderId: 357149834,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘jipgN97TiAyS8jaVQ11i3c0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: true,
closePosition: false,
side: ‘SELL’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692861874
}
]

step 5-2 - there is one and it works correctly.
ALL FINE

[
[Object: null prototype] {
orderId: 357150011,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘bsnZaq41mZijGSREARACfl0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘BUY’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692862556
},

step 5-3 - there is such and it works correctly.
ALLFINE

[Object: null prototype] {
orderId: 357150014,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘CxutW8GyscQVSkTo2gHYyF1’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘SELL’,
positionSide: ‘SHORT’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692862557
}
]

step 6 - The script step 5 starts same time again, but why ??? Just because we got error step 4-1. So, we repeat the scenario for closing a long position and opening new orders.

And the funny thing is that the same error step 1-1 had no consequences.

Let’s see what happened.

  1. The script closes the newly opened position long. Closes just for fun. Okay, now on Binance I got only 1 work position short

[4:21: LONG STOPLOSS IS ACTIVATED.
------------------- GTCUSDT CLOSE LONG -------------------
[
[Object: null prototype] {
orderId: 357152067,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘Z22qKoYVibgSER71vJbDPY0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: true,
closePosition: false,
side: ‘SELL’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692875260
}
]

step 6-1 - Okay, we just closed the long position and are now entering the long position again.

[
[Object: null prototype] {
orderId: 357152130,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘sCu4TbNFR4yIf79kSLRqHu0’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘BUY’,
positionSide: ‘LONG’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692875955
},

step 6-2 - And now about the bad. Another short position opens, but I still have a working short position and now there will be two.

[Object: null prototype] {
orderId: 357152129,
symbol: ‘GTCUSDT’,
status: ‘NEW’,
clientOrderId: ‘Na6dfiJl9T8Rya9oRyrH5e1’,
price: ‘0’,
avgPrice: ‘0.0000’,
origQty: ‘1’,
executedQty: ‘0’,
cumQty: ‘0’,
cumQuote: ‘0’,
timeInForce: ‘GTC’,
type: ‘MARKET’,
reduceOnly: false,
closePosition: false,
side: ‘SELL’,
positionSide: ‘SHORT’,
stopPrice: ‘0’,
workingType: ‘CONTRACT_PRICE’,
priceProtect: false,
origType: ‘MARKET’,
updateTime: 1634692875955
}
]

Then the script forgets about orderId: 357150014 and only works with orderId: 357152129.

Thanks to all, I’ll get liquidation for orderId: 357150014

Hi,

Can you give further details to help diagnose the issue?

  • Which endpoint is failing?
  • Could you provide a sample request that is failing?
  • Has this happened previously or is it recent?

this is the first version of my bot and in general it works perfectly. For example, if you run it for 2-3 coins, it works PERFECTLY, but for 15 positions, the whole breaks with the activation of the CLOSE SHORT POSITION script and CODE -2022 ReduceOnly rejected crashes.

What happens in fact on the stock exchange. A SHORT position closes and opens an order, which leads to an extra increase in the position, as well as the script does not control this position and the exchange will liquidate it soon if I do not close it with my hands.

 > if (Number(users[i].takeProfitLong) <= Number(courseFutures[users[i].pair])) {
>                 console.log(chalk.keyword(`red`).bold(`------------------- ${users[i].pair} CLOSE LONG [TAKEPROFIT LONG] -------------------`))
>                 console.info(await binance.futuresMarketBuy(users[i].pair, users[i].amount, { positionSide: "LONG" }))

Have a look at this thread regarding the error you are facing.

If you are still having issues or do not understand what is said, please let me know.

create position SHORT:
{
symbol = symbol,
side = ‘BUY’,
positionSide = SHORT,
type = ‘MARKET’,
quantity = -quantity or quantity???
}

Quantity should be positive.

close position SHORT:
{
symbol = symbol,
side = ‘BUY’,
positionSide = SHORT,
type = ‘MARKET’,
quantity = -quantity or quantity???
}

Change side=“BUY” to side=“SELL” and quantity should once again be positive.

Ok, thank you so much. Can i ask last question.
FuturesMarketSell/Buy - for ONE-WAY-MODE?
FuturesMultipleOrder - for Hedge Mode?

FuturesMarketSell/Buy can be used for both one-way-mode and hedge mode.

FuturesMultipleOrder is an extension of FuturesMarketSell/Buy, which allows multiple orders to be placed at once.

now I absolutely do not understand why the message “code 2022 Reduce only” appears

now my code right?

let orders = [{
                        symbol: `${x.pair}`,
                        positionSide: 'LONG',
                        side: 'SELL',
                        type: 'MARKET',
                        quantity: `${x.amount}`
                    },
                    {
                        symbol: `${x.pair}`,
                        positionSide: 'SHORT',
                        side: 'BUY',
                        type: 'MARKET',
                        quantity: `${x.amount}`
                    }
                ]

Error 2022 is thrown when the parameter reduceOnly is set to TRUE while in Hedge Mode.

Can you confirm that reduceOnly is not being set to TRUE before sending the request to the API?