How can I determine if the order has been closed?

I open a long order with tp and sl , I want to know if it hit the take profit or stop loss (status closed) for open another order
I use this code but he return filled
from binance.um_futures import UMFutures
def check_order_status(order_id): # true sil atouché stoploss ou takeprofit – false sil est toujours ouvert
global symbol
try:
order = um_futures_client.query_order(
symbol=symbol, orderId=order_id, recvWindow=6000
)
print(order)
# Verifier si l’ordre a ete rempli (et donc ferme)
if order[‘status’] == “FILLED”:
print(“premier L’ordre a ete rempli.”)
return True

    # Verifier si le stop-loss a ete touche
    if order['status'] == "STOP_LOSS_HIT":
        print("premier Le stop-loss a ete touche.")
        return True

    # Verifier si le take-profit a ete touche
    if order['status'] == "TAKE_PROFIT_HIT":
        print("premier Le take-profit a ete touche.")
        return True

    return False

except Exception as e:
    print("Erreur lors de la verification de l'etat de l'ordre:", e)
    return False

Hey,
According to the Binance Futures API documentation, a transaction can have the following statuses:

  • NEW
  • PARTIALLY_FILLED
  • FILLED
  • CANCELED
  • REJECTED
  • EXPIRED
  • EXPIRED_IN_MATCH

If the transaction has a FILLED status, it means that the order has been completely executed and a trade has occurred. You can then compare the executed price with the price you set for the take profit or stop loss order.

If you placed the order via the API, you would have been able to set the order type as either TAKE_PROFIT/TAKE_PROFIT_MARKET or STOP/STOP_MARKET. When the order is filled, it means that the specific order type you set has been triggered. You can checkout the documentation.

1 Like

I had forgotten that I needed to retrieve the status of the take porfit order lol , I will test it, thank you very much for your response