Hello Guys,
I’m turning to you because I’m stuck in a small dev on which I’m working.
I tried to place some orders on Binance Futures but I face some issues.
There is the scheme I want to have:
- Place LONG/SHORT limit order → Works
- Place “Limit Order” to reduce the current position orders (it acts like a Take Profit) → Works
- Place a 2nd “Limit Order” to reduce the current position orders (it acts like a Take Profit) → Works
- Place a “Take Profit Market” order when the 3rd level of profit is reach and then close all orders for that coin/token → It failed here.
- Place a “Stop Market” order → works
I’m using the binance_f library for python (Binance API Documentation
code for step 1:
def submit_intial_order(client, price, positionSide, qty, market, _type="LIMIT"):
_side = of.get_side(positionSide)
client.post_order(symbol=market,
side=_side,
ordertype=_type,
timeInForce="GTC",
quantity=qty,
price=price,
)
code for step 2 & 3:
def submit_tp_order(client, price, positionSide, qty, market, _type="TAKE_PROFIT"):
_side = of.get_side(positionSide)
client.post_order(symbol=market,
side="SELL",
ordertype=_type,
timeInForce="GTC",
quantity=qty,
reduceOnly=True,
price=price,
stopPrice=price,
closePosition=False)
code for step 4
def submit_final_tp_order(client, positionSide, stopPrice, market, _type="TAKE_PROFIT_MARKET"):
_side = of.get_side(positionSide)
client.post_order(symbol=market,
side=_side,
ordertype=_type,
stopPrice=stopPrice,
workingType="CONTRACT_PRICE",
closePosition=True)
At this point I’m always getting “(‘ExecuteError’, ‘[Executing] -2021: Order would immediately trigger.’)”.
Does this last “take profit” be created after the position is opened or do I miss some parameters in the orders ?
Last question, if I manually close the position, my intermediate “Take profit”