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?