Binance is confusing orderId's and keeps order alive although it's triggered

I’m using two take profits (limit) and two stop-limit orders.
My logic is: when TP1 is filled, close STOP1, when TP2 is filled, close position + all open orders.
I tested this intensively on testnet and it worked fine.
Now I switched to production version and the logic is totally twisted.
How is this possible?
What happens now is that when TP1 is hit, TP2 will be closed, the Stops will be closed, but TP1 ist still open( !!! ), and the trade is still open. 1 of 8 times it works correctly though. Is the binance programming that ragged??

    if json_message['o']['i'] == STOP2_orderId:
        response_delete_orders_all = sr.send_signed_request('DELETE', '/fapi/v1/allOpenOrders', { "symbol": symbol })
        print(response_delete_orders_all)
        ws.keep_running = False

    elif json_message['o']['i'] == TP_1_orderId: 
        response_delete_orders_stop = sr.send_signed_request('DELETE', '/fapi/v1/order', { "symbol": symbol, "orderId": STOP_orderId  })
        print(response_delete_orders_stop)
        
    elif json_message['o']['i'] == TP_2_orderId: 
        response_delete_orders = sr.send_signed_request('DELETE', '/fapi/v1/allOpenOrders', { "symbol": symbol })
        print(response_delete_orders)
        ws.keep_running = False

When it doesn’t work:

2021-06-20 11:18:15
{'symbol': 'ETHUSDT', 'Filled avgPrice: ': '2178.30000'}
TP_1 orderID:
8389765500492035992
TP_2 orderID:
8389765500492036183
STOP orderID:
8389765500492036306
STOP2 orderID:
8389765500492036398
Position amount: 0.010
listenKey: i8KiFvXnA81ShIZ7w7W24tIhU3uund0B9zmRuSEInDzP7MfGsQ98GdFuZQr5nDEq
websocket connected
'Order Update: SELL LIMIT FILLED'
Realized Profit: 0.01850000
{'E': 1624181299973,
 'T': 1624181299970,
 'e': 'ORDER_TRADE_UPDATE',
 'o': {'L': '2182',
       'N': 'USDT',
       'R': False,
       'S': 'SELL',
       'T': 1624181299970,
       'X': 'FILLED',
       'a': '10.94500',
       'ap': '2182',
       'b': '0',
       'c': 'J0hyqYgYmTmcWDkwiaLn0w',
       'cp': False,
       'f': 'GTC',
       'i': 8389765500492035992,
       'l': '0.005',
       'm': True,
       'n': '0.00218200',
       'o': 'LIMIT',
       'ot': 'LIMIT',
       'p': '2182',
       'pP': False,
       'ps': 'BOTH',
       'q': '0.005',
       'rp': '0.01850000',
       's': 'ETHUSDT',
       'si': 0,
       'sp': '0',
       'ss': 0,
       't': 745531294,
       'wt': 'CONTRACT_PRICE',
       'x': 'TRADE',
       'z': '0.005'}}
{'orderId': 8389765500492036306, 'symbol': 'ETHUSDT', 'status': 'CANCELED', 'clientOrderId': '2078PoU42l88KzOEBUSWjJ', 'price': '2174', 'avgPrice': '0.00000', 'origQty': '0.005', 'executedQty': '0', 'cumQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'STOP', 'reduceOnly': False, 'closePosition': False, 'side': 'SELL', 'positionSide': 'BOTH', 'stopPrice': '2175', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'STOP', 'updateTime': 1624181300455}
'Order Update: SELL STOP CANCELED'
Realized Profit: 0
{'E': 1624181300461,
 'T': 1624181300455,
 'e': 'ORDER_TRADE_UPDATE',
 'o': {'L': '0',
       'R': False,
       'S': 'SELL',
       'T': 1624181300455,
       'X': 'CANCELED',
       'a': '10.94500',
       'ap': '0',
       'b': '0',
       'c': '2078PoU42l88KzOEBUSWjJ',
       'cp': False,
       'f': 'GTC',
       'i': 8389765500492036306,
       'l': '0',
       'm': False,
       'o': 'STOP',
       'ot': 'STOP',
       'p': '2174',
       'pP': False,
       'ps': 'BOTH',
       'q': '0.005',
       'rp': '0',
       's': 'ETHUSDT',
       'si': 0,
       'sp': '2175',
       'ss': 0,
       't': 0,
       'wt': 'CONTRACT_PRICE',
       'x': 'CANCELED',
       'z': '0'}}

Before the trigger:

After trigger:

Again - sometimes the logic works as it shoud, but very rarely. What is the problem?

Hi. I’m not so sure how you got those json_message and how the other parts of the program work but my first guess is about the order status. It is possible that the websocket stream receives the records with status = PARTIALLY_FILLED instead of FILLED. Could you check if this part is handled properly?

I need to reproduce it later to check for the partial fill. But I’m very sure it is not the case . 1) why should the partial fill happen so many times in a row? 2) why would the other orders getting triggered with a partial fill? Doesn’t make sense to me

It is possible to have multiple partial fill records when the liquidity is low. But if the condition check for when TP1 is filled is implemented with the full text matching, it should work fine and we will have to figure out what is the root cause of the error.

10 times in a row low liquidity with order size of 0.01 of ETHUSDT on Binance?? Cmon

I tried to reproduce the situation but now binance opens only one take profit limit order instead of two.
I tried it with two stop limits and also with one stop market.

Response from the two TP’s:

TP_1 orderID:
{‘orderId’: 8389765500716955960, ‘symbol’: ‘ETHUSDT’, ‘status’: ‘NEW’, ‘clientOrderId’: ‘IMREuFgA2SKK7uPOW5nmug’, ‘price’: ‘1899’, ‘avgPrice’: ‘0.00000’, ‘origQty’: ‘0.005’, ‘executedQty’: ‘0’, ‘cumQty’: ‘0’, ‘cumQuote’: ‘0’, ‘timeInForce’: ‘GTC’, ‘type’: ‘LIMIT’, ‘reduceOnly’: False, ‘closePosition’: False, ‘side’: ‘BUY’, ‘positionSide’: ‘BOTH’, ‘stopPrice’: ‘0’, ‘workingType’: ‘CONTRACT_PRICE’, ‘priceProtect’: False, ‘origType’: ‘LIMIT’, ‘updateTime’: 1624380958015}
TP_2 orderID:
{‘orderId’: 8389765500716956353, ‘symbol’: ‘ETHUSDT’, ‘status’: ‘NEW’, ‘clientOrderId’: ‘oc3MOJbqVcNelkpBwYfE5V’, ‘price’: ‘1890’, ‘avgPrice’: ‘0.00000’, ‘origQty’: ‘0.005’, ‘executedQty’: ‘0’, ‘cumQty’: ‘0’, ‘cumQuote’: ‘0’, ‘timeInForce’: ‘GTC’, ‘type’: ‘LIMIT’, ‘reduceOnly’: False, ‘closePosition’: False, ‘side’: ‘BUY’, ‘positionSide’: ‘BOTH’, ‘stopPrice’: ‘0’, ‘workingType’: ‘CONTRACT_PRICE’, ‘priceProtect’: False, ‘origType’: ‘LIMIT’, ‘updateTime’: 1624380958339}

But only 1 TP on the chart / open orders list:

Alright, order status may not be the case. Can you explain more about how the 2nd scenario related to original issue?
Original scenario includes 2 take profit orders and 2 stop limit orders. Now you mentioned you used 1 take profit order plus 2 stop limit order and 1 stop loss order. However, the response includes 2 take profit order? I’m confused…

It’s so far related because it’s the same code. I wanted to reproduce it to give you more information on the initial problem. Now, there was a new problem. I just tested it in two variations - with stop market and two stop limit orders (as initial). Both versions led to the same result that one of the take profit orders now are not opened on the chart although I get the response that they are opened. Anyway, I don’t see you trying to investigate in any way.
I just figured out that the missing limit order is a cache/ browser problem? When I open a trade - the limit order is missing - I refresh the browser and the order appears. Do you know how to get rid of that? I cleared the cache but the problem still exists. It’s Chrome Version 91.0.4472.106

Could you now please tell me what you need to get down to the initial problem ?

if you are reporting a different issue, please try to open another topic. It’s not easy to understand when you are mixing multi concerns together.

It’s also very import to give us clear steps to reproduce the issue.

Thanks for answering. You are very professional

  • is the order with price 2182 still can be found on trading chart?
  • if so, can you check the status of the order via API?

thanks

No, the order doesn’t exist anymore.