I want to create a function in python that can place the future order with target and stop loss. Once the target or stop loss hit, It should close the order. I have tried to create a function but it did not work
def place_future_order(symbol,side,quantity,target,sl):
order1=binance_client.futures_create_order(symbol=symbol, side=side, type="MARKET", quantity=quantity)
print(order1)
while True:
response = binance_client.get_open_orders()
if(response==[]):
print("ORDER FILED")
break
time.sleep(1)
time.sleep(1)
order2=binance_client.futures_create_order(symbol=symbol, side=side, type="TAKE_PROFIT_MARKET", quantity=quantity, stopPrice=target)
print(order2)
order3=binance_client.futures_create_order(symbol=symbol, side=side, type="STOP_MARKET", quantity=quantity, stopPrice=sl)
print(order3)