Issue placing "Take Profit Market" order

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:

  1. Place LONG/SHORT limit order → Works
  2. Place “Limit Order” to reduce the current position orders (it acts like a Take Profit) → Works
  3. Place a 2nd “Limit Order” to reduce the current position orders (it acts like a Take Profit) → Works
  4. 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.
  5. 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 :slight_smile:

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”

Order would immediately trigger

This occurs when the stop order requested would be immediately executed upon being placed.

Could you provide a sample with the parameters passed to the API and the current price of the symbol is question to further diagnose the cause of the issue?

Hello,

@tantialex this is the parameter I used for my test:

type
LONG
entry_price
63350,56$
tp1
63933,69$
tp2
64200,25$
tp3
65576,51$
sl
63000,99$
leverage
20

Regards,

Small up for help :confused:

When placing a TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT order, the stopPrice parameter is relative to the current price of the symbol.

A BUY order should have a stopPrice < marketPrice
A SELL order should have a stopPrice > marketPrice

So what’s the best way to do so ? I tried/search TAKE_PROFIT_LIMIT in the doc and this type or order doesn’t exist.

So how to open an order with a Limit order and then configure a TP and SL that will close the position when triggered ? Like the TP/SN on the web interface?

Binance Futures does not support One-Cancels-the-Other (OCO) orders.

Here is a guide on how to implement it manually.

That’s not the point, I should be able to set a “Take_profit” that close my position (not kill all the pending order). I can kill the pending order after that.

But if you look on the browser console it’s the same code send by the website. Really strange.

Your initial logic is correct and valid. However, the issue you encountered suggests that either the stopPrice or the order side you are sending do not match.

Adjust your logs and confirm that the below statements are correct.

A BUY order should have a stopPrice < marketPrice
A SELL order should have a stopPrice > marketPrice

If you still encounter this issue, please include the RAW request so we can further diagnose (including url and query string, excluding sensitive information). Including code will not help as there are other factors that can cause the issue.

Hello @tantialex thanks for you help, one part is solved now. I had a mismatch with the order type.

Now this is what I have:

I have well one open position and 3 Take profit configured.

I just have an issue now with the Stop Loss. Once I got a “(‘ExecuteError’, ‘[Executing] -2021: Order would immediately trigger.’)”,

With a LONG do I have to use a “BUY” order for a STOP LOSS ?

A STOP_LOSS order can be placed as either a BUY or a SELL on a LONG position. The deciding factor is whether you want to increase your position or reduce it.

If you want to increase your LONG position, you may place a BUY STOP_LOSS order with the stop_price > market_price.
If you want to reduce your LONG position, you may place a SELL STOP_LOSS order with the stop_price < market_price.