ViewBlock / binance-api-node

:chart: A complete and heavily tested wrapper with typings for the Binance API.
657 stars 502 forks source link

How to create valid takeprofit and stoploss in futures? #661

Open Gtompa opened 4 months ago

Gtompa commented 4 months ago

I am writing a trading bot, but faced with such a problem that my stoploss and takeprofit by binance itself for the reason: "Expired", no time limits I do not set. Most likely I create the order incorrectly, so I want to ask how to do it correctly? At the moment I create them one by one all together like this:

   ` const order = await this.client.futuresOrder({
      type: "STOP",
      price: this.formatByPrecision(orderPrice, pricePrecision),
      symbol: pair.ticker,
      stopPrice: enterStopPrice,
      quantity,
      side: logSide,
      priceProtect: "TRUE",
  });

  await this.client.futuresOrder({
    type: "STOP_MARKET",
    stopPrice: loseStopPrice,
    symbol: pair.ticker,
    side: leaveSide,
    closePosition: "true",
  });

  await this.client.futuresOrder({
    type: "TAKE_PROFIT",
    stopPrice: this.formatByPrecision(tp + cf, pricePrecision),
    quantity,
    price: this.formatByPrecision(tp, pricePrecision),
    symbol: pair.ticker,
    side: leaveSide,
  });`

The model of work of these orders is as follows, for example, I want to open a buy transaction on the coin "AAAUSDT", the entry point I assign the price of 101, calculate take profit at the price of 105, and stop loss at the price of 100. I need that there was no slippage, so I want all these orders triggered immediately when entering the transaction, what am I doing wrong?

After opening a trade binance closes my stoplosses and takeprofits, thus I do not control my losses. Who can help me how to place such orders correctly?