1

How can I change the take profit or stop loss of an order already created via ccxt python in Binance futures?

I would like an already created order to be able to change the stop loss, as if I did it from the binance web cli, there is some way, I create my order like this

exchange.create_order(symbol=par, type='limit', side=side, price = precio, amount= monto, params={})

When detecting a certain pattern I would like to update the SL and TP, it's possible?

I have not found information in the ccxt wiki

2 Answers2

0

There is an edit_order function that you may want to try.

import ccxt

exchange = ccxt.binanceusdm()

exchange.apiKey = 'YOUR_API_KEY'
exchange.secret = 'YOUR_API_SECRET'

symbol = 'BTC/USDT'
order_id = 'ORDER_ID'
order_type = 'limit'
side = 'buy'
amount = 0.001
price = 16000

stop_loss = 15000
take_profit = 17000

exchange.edit_order(order_id, symbol, order_type, side, amount, price, {'stopLossPrice': stop_loss, 'takeProfitPrice': take_profit})
0

Binance futures api currently does not support the creation of an order with take profit and stop loss

Binance futures api currently does not support the creation of an order with take profit and stop loss, nor the following modification where you could add profit and stop loss orders.

The mentioned implementation is not functional, because the edit_order() method internally calls the REST api method "Modify Order (TRADE)", which has the following possible input parameters:

  • orderId
  • origClientOrderId
  • symbol
  • side
  • quantity
  • price
  • recvWindow
  • timestamp

Attribute "stopLossPrice" and "takeProfitPrice" does not supported actually via REST API.

Documentation: Binance api - modify order trade

Proposal solution

The solution is, for example, to switch to the Bybit exchange, which supports insertion limit orders with profit and stop loss when entering an order via the API.

Documentation: Bybit api - create-order