Got error APIError(code=-1013): The relationship of the prices for the orders is not correct when trying to place an OCO order

Hi all!

I have been several days testing the possible combinations and I am not able to put an oco order.

Basically, after adjusting the quantities to meet the MIN_NOTIONAL, STEP_SIZE and similar filters for testing, it all boils down to this:

Test 1 vars:
side=SELL, stopPrice=1.619, price=1.535, stopLimitPrice=1.629, stopLimitTimeInForce=GTC.

Error obtained:
binance.exceptions.BinanceAPIException: APIError(code=-1013): The relationship of the prices for the orders is not correct.

Test 2 vars:
side=SELL, stopPrice=1.629, price=1.535, stopLimitPrice=1.619, stopLimitTimeInForce=GTC.

Error obtained:
binance.exceptions.BinanceAPIException: APIError(code=-1013): The relationship of the prices for the orders is not correct.

I do not understand the reason for the error, if I am complying with the parameters indicated here on the test 1 (if I am not wrong…)

Price Restrictions:
SELL: Limit Price > Last Price > Stop Price
BUY: Limit Price < Last Price < Stop Price

I’m working with binance-python api framework and the involved code is:

	TPOrder = binance.create_oco_order(
		symbol=symbol,
		side=Client.SIDE_SELL,
		stopPrice=TP_price_adjusted, 
		quantity=qty,
		price=actualPrice, 
		stopLimitPrice=TP_price, 
		stopLimitTimeInForce=Client.TIME_IN_FORCE_GTC,	
	)

Can someone, help me? What am I ignoring, missing or understanding?

OCO is composed by two orders, in your case, since you’re using stopLimitPrice, these two orders are LIMIT_MAKER + STOP_LOSS_LIMIT. When side=SELL, it means:

  • You’ll place the LIMIT_MAKER when Last Price goes up and matches Limit Price (price).
  • You’ll trigger the STOP_LOSS_LIMIT when Last Price unfortunately goes down but matches your stopPrice so that you don’t lose too much money by automatically placing a stop limit order with price=stopLimitPrice (stopLimitPrice < stopPrice, otherwise your order wouldn’t be a limit type of order).

Therefore, at the moment of order placement, the rule needs to be “Limit Price > Last Price > Stop Price”.

Test 1 vars:
side=SELL, stopPrice=1.619, price=1.535, stopLimitPrice=1.629, stopLimitTimeInForce=GTC.

In your example, the prices are failing the rule, the limit price=1.535 is < stopPrice=1.619. Depending on the Last price, it would probably work for side=BUY instead.