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.
- 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