Order would immediately trigger

Hi Guys!
I know there are many topic about this error, still I can’t figure out why I’m getting this error :
data: { code: -2021, msg: ‘Order would immediately trigger.’ }

As I know, I cannot create sl/tp order together so I posted 3 different order: 1 limit 1 stop 1 take profit

Here is my limit order :
{
type: ‘LIMIT’,
side: ‘SELL’,
symbol: ‘BTCUSDT’,
price: ‘17144.50’,
timeInForce: ‘GTC’,
recvWindow: 5000,
quantity: 0.01
}
This was successfully posted on testnet.

Here is my stop order:
{
type: ‘STOP’,
side: ‘SELL’,
symbol: ‘BTCUSDT’,
price: ‘17144.50’,
timeInForce: ‘GTC’,
recvWindow: 5000,
quantity: 0.01,
stopPrice: 17212
}
Stop order already sent a -2021 error.

And here is my take profit order:
{
type: ‘TAKE_PROFIT’,
side: ‘SELL’,
symbol: ‘BTCUSDT’,
price: ‘17144.50’,
timeInForce: ‘GTC’,
recvWindow: 5000,
quantity: 0.01,
stopPrice: 17058
}

Probably the problem is with me and my code , so can you help me with this problem please? :slight_smile:

An here is my order:

async placeOrder(symbol, side) {
var data = {};

  var price = await this.getBidAsk(symbol);
  price = side === 'BUY' ? price.bid : price.ask;
  data['type'] = 'LIMIT';
  data['side'] = side;
  data['symbol'] = symbol;
  data['price'] = price;
  data['timeInForce'] = 'GTC';
  data['recvWindow'] = 5000;
  data['quantity'] = 0.01;

  let order = await this._makeRequest('POST', '/fapi/v1/order', data);
  console.log(data);

  setTimeout(async () => {
     var sp = await this.getBidAsk(symbol);
     sp = sp.bid;

     data['type'] = 'STOP';
     data['stopPrice'] = side === 'BUY' ? Math.round(sp * 0.996) : Math.round(sp * 1.004);
     order = await this._makeRequest('POST', '/fapi/v1/order', data);
     console.log(data);

     data['type'] = 'TAKE_PROFIT';
     data['stopPrice'] = side === 'BUY' ? Math.round(sp * 1.005) : Math.round(sp * 0.995);
     order = await this._makeRequest('POST', '/fapi/v1/order', data);
     console.log(data);
  }, 5000);

  return order.data;

}
As I see this criteria is fulfilled:

  • STOP, STOP_MARKET:
    * BUY: latest price (“MARK_PRICE” or “CONTRACT_PRICE”) >= stopPrice
    * SELL: latest price (“MARK_PRICE” or “CONTRACT_PRICE”) <= stopPrice
  • TAKE_PROFIT, TAKE_PROFIT_MARKET:
    * BUY: latest price (“MARK_PRICE” or “CONTRACT_PRICE”) <= stopPrice
    * SELL: latest price (“MARK_PRICE” or “CONTRACT_PRICE”) >= stopPrice

Thx for helping me :slight_smile:

You need to send side:"BUY" for stop order since you open a short position. Otherwise you will get the error

1 Like