I am trying to place a stop loss and take profit while opening a position, is that possible and if yes, how?
Please do not refer me back to the documentation, it does not help me.
Let’s say I want to open a position like this:
info = client.futures_create_order(
symbol=‘BNBUSDT’,
side=SIDE_BUY,
type=ORDER_TYPE_MARKET,
quantity=5,
)
Can I also create a stop loss in the same function call, or would I have to do that with a seperate function call?
After extensive trial and error I think I got the hang of the Trailing Stop Loss, however it seems even if the position is closed the TSL remains open, even if I pass reduceOnly=‘true’.
My code:
def trailing_stop_loss(symbol, price, quantity):
I have made it somewhat work, however I encounter a different issue now.
When my position gets closed i want my stop loss orders to be closed as well. I realized it like this:
while True:
orders = client.futures_get_open_orders(symbol=symbol)
order_ids = [order['clientOrderId'] for order in orders]
if client.futures_position_information(symbol=symbol)[0]['positionAmt'] == '0.0':
client.futures_cancel_orders(symbol=symbol, origClientOrderIdList=order_ids, recvWindows=5000, timestamp=time.time()*1000)
break;
This all works until I make the call to cancel the outstanding orders. binance.exceptions.BinanceAPIException: APIError(code=-1022): Signature for this request is not valid.
What am, I doing wrong?
client.futures_cancel_all_open_orders(symbol=symbol)
Is working for me and I will just use that. Note sure why the other call failed tho,