How to implement OTOCO(TP/SL) orders using API

I was running into the same issue and worked out that it can be done without the need for a socket connection to monitor whether or not one of the TP/SL has been filled, in order to cancel the other.

It does require three separate calls to the api to create each as the solved answer points out, but the parameters sent in the calls can be set as such that one will cancel the other two if it executes.

For example, the SL being hit will cancel the original order and the TP and the TP being hit will cancel the original order and the SL, etc. Here are the parameters I used in each call to achieve this (with example values):

Original order -

  • symbol=BNBUSDT

  • side=BUY

  • positionSide=BOTH

  • type=MARKET

  • quantity=1

  • reduceOnly=false

SL Order -

  • symbol=BNBUSDT

  • side=SELL

  • positionSide=BOTH

  • type=STOP_MARKET

  • timeInForce= GTE_GTC

  • quantity=1

  • reduceOnly=true

  • stopPrice=(your stop price)

  • workingType= MARK_PRICE

TP Order -

  • symbol=BNBUSDT

  • side=SELL

  • positionSide=BOTH

  • type=TAKE_PROFIT_MARKET

  • timeInForce= GTE_GTC

  • quantity=1

  • reduceOnly=true

  • stopPrice=(your take profit price)

  • workingType= MARK_PRICE

There isn’t two separate calls in the UI as pointed out in this thread, rather one call with a payload with three parts, one for each order entered in the UI (the trade, stop loss, take profit).

To see this, have a look in the network call in developer tools. In the call (place-order) under its payload tab, you’ll see it passes a list called ‘subOrderList’. Inside this are the three JSON blobs for each respective order. You’ll find the parameters needed in there.

Hopefully this helps anyone else running into this issue :slight_smile:

10 Likes

Can you post a link to where is the "network call in developer tools. In the call (place-order) under its payload tab, you’ll see it passes a list called ‘subOrderList’. " It would be verry helpful or an example of how you passed the three json files in an order.

You say you send 3 separate orders but how is the link between the TP and SL orders and their parent order specified?

This works for me, thanks a million for sharing.

Can I get your contact info ?

Would it work if I change original order type from MARKET to LIMIT?

I don’t have Facebook, sorry. What is it you are actually trying to achieve here? Are you wanting to create an order in Binance via the api that includes a TP/SL?

I am calling the Binance api to do that, but in order to add the TP/SL it requires two additional calls. All of the required values are sent as url parameters in each of the calls.

So if you look in each of the JSON parts for the trade, take profit and stop loss that you get via the network tab in developer tools you will see all of the parameters and their values you will need to construct each url to make each call with.