Automatically cancel take profit and stop loss orders when closing position

what library do you use? can you help with a link to it? i cant find any library that supports GTE_GTC

I can’t help you with a link. I just did some researches across different sites and implemented what I needed on my own.

By default Binance doesn’t close the TAKE_PROFIT_MARKET or STOP_MARKET after position is closed… you need to manually close those orders, you can pull the current opened orders and filter them based on the positionSide (SELL / LONG / BOTH) and origType (TAKE_PROFIT_MARKET / STOP_MARKET) and you can get the orderId for those orders and batch cancel them or cancel them one by one

you check my original answer here.

const position = 'LONG' // LONG, SHORT, BOTH

axios
.get('https://fapi.binance.com/fapi/v1/openOrders', {
  params: {
    symbol: 'BTCUSDT'
  }
})
.then(({ data }) => {
  const orderIds = data
    .filter(
      ({ positionSide, origType }) =>
        positionSide === position &&
        ['TAKE_PROFIT_MARKET', 'STOP_MARKET'].includes(origType)
    )
    .map(({ orderId }) => orderId)

  // Use batch cancel or cancel order one by one
  console.log('orderIds', orderIds)
})

ordemSaidaCompraGain = client.futures_create_order(
symbol = symbol,
side = ‘SELL’,
positionSide=‘LONG’,
type=‘TAKE_PROFIT_MARKET’,
closePosition=True,
stopPrice = round(entradaComprado+pips, 3),
timeInForce=‘GTE_GTC’
)

    ordemSaidaCompraLoss = client.futures_create_order(
        symbol = symbol,
        side = 'SELL',
        positionSide='LONG',
        type='STOP_MARKET',
        closePosition=True,
        stopPrice = round(entradaComprado-2*pips, 3),
        timeInForce='GTE_GTC'
    )