ccxt icon indicating copy to clipboard operation
ccxt copied to clipboard

Possible to cancel all STOP order instead of both STOP and TAKE PROFIT and TRAILING STOP order in FTX

Open jamezun opened this issue 4 years ago • 4 comments

  • OS: Win10
  • Programming Language version: Python 3
  • CCXT version: Latest

In FTX,

I am able to cancel all conditional trade with the following code:

exchange.cancel_all_orders(symbol,params={'conditionalOrdersOnly': False})

But is it possible to cancel all STOP order instead of both STOP and TAKE PROFIT and TRAILING STOP order? or the only way is to use the cancel_order() function together with the order ID argument?

jamezun avatar Mar 12 '22 16:03 jamezun

That might be achieved with different ways. With that exact method you use, as API docs says here you can set :

  • side : which side or orders you want to cancel (buy or sell, depending which side you have traded)
  • conditionalOrdersOnly : restrict to cancelling conditional orders only
  • limitOrdersOnly : whether to cancel non-conditional orders only

So, depending if you mean 'stoploss' order in the 'stop' order, then you might mean this

exchange.cancel_all_orders(symbol,params={'conditionalOrdersOnly': True, 'limitOrdersOnly': True, 'side': ... })

Please let me know if I correctly answered your question.

Also, it can be done with other ways - there are other types of endpoints here (i.e. Cancel open trigger order) which allows you to cancel order by id. So, you can either: a) fetch open orders to get id or b) save id from 'createOrder'

and then cancel the desired order by id.

ttodua avatar Mar 12 '22 19:03 ttodua

That might be achieved with different ways. With that exact method you use, as API docs says here you can set :

* `side` : which side or orders you want to cancel (`buy` or `sell`, depending which side you have traded)

* `conditionalOrdersOnly` : restrict to cancelling conditional orders only

* `limitOrdersOnly` : whether to cancel non-conditional orders only

So, depending if you mean 'stoploss' order in the 'stop' order, then you might mean this

exchange.cancel_all_orders(symbol,params={'conditionalOrdersOnly': True, 'limitOrdersOnly': True, 'side': ... })

Please let me know if I correctly answered your question.

Also, it can be done with other ways - there are other types of endpoints here (i.e. Cancel open trigger order) which allows you to cancel order by id. So, you can either: a) fetch open orders to get id or b) save id from 'createOrder'

and then cancel the desired order by id.

Thanks for your reply! Let say I currently have a STOP MARKET sell order, a TAKE PROFIT sell order, and a TRAILING sell order, how could I just choose to remove the STOP sell order only or just remove the TRAILING sell order only or just remove the TAKE PROFIT only just by using the function cancel_all_orders()? Is that possible?

I tried to run:

exchange.cancel_all_orders(symbol,params={'conditionalOrdersOnly': True, 'limitOrdersOnly': True, 'side': ..

But error:

ccxt.base.errors.ExchangeError: ftx {"success":false,"error":"Must cancel either limit orders or conditional orders"}

and also what do you mean save id from 'createOrder'? you mean the id will be automatically saved in some variable for me to retrieve?

jamezun avatar Mar 12 '22 19:03 jamezun

when you create an order with createOrder it returns the order-id, which you can save in variable and reference later:

myOrder = exchange.createOrder(...)
# myOrder.id <--- this will be order id

So, when you create a stop-market sell order with createOrder() method, then at that moment save the order-object in variable and then use that order-object's ID to call the 'cancel_order' by 'id'. that might be easy solution in your case. that is preferred over 'cancel_all_orders' typically. ( btw, sorry, I wanted to type False in my first comment, instead of True however, if you still need this last endpoint to use, i'll try to figure it out, if that's possible and provide the script sample by tomorrow per your explanation. but if cancel_order will be better fit for you, then no need to use cancel_all_orders. ) let me know your thoughts.

ttodua avatar Mar 12 '22 21:03 ttodua

when you create an order with createOrder it returns the order-id, which you can save in variable and reference later:

myOrder = exchange.createOrder(...)
# myOrder.id <--- this will be order id

So, when you create a stop-market sell order with createOrder() method, then at that moment save the order-object in variable and then use that order-object's ID to call the 'cancel_order' by 'id'. that might be easy solution in your case. that is preferred over 'cancel_all_orders' typically. ( btw, sorry, I wanted to type False in my first comment, instead of True however, if you still need this last endpoint to use, i'll try to figure it out, if that's possible and provide the script sample by tomorrow per your explanation. but if cancel_order will be better fit for you, then no need to use cancel_all_orders. ) let me know your thoughts.

You suggested way helps a lot but I would like to see if cancel_all_orders() can work as well so I do not have to bother to manipulate the id if that does not require you a massive load of work to check it out.. thanks!

jamezun avatar Mar 13 '22 12:03 jamezun

Above replies have been maximum that could have been done with FTX in this specific case (as FTX doesn't seem to natively support the very specific command you want). I'll mark the topic close, but will be still possible for anyone to post their comments (if they want).

ttodua avatar Aug 12 '22 15:08 ttodua

when you create an order with createOrder it returns the order-id, which you can save in variable and reference later:

myOrder = exchange.createOrder(...)
# myOrder.id <--- this will be order id

So, when you create a stop-market sell order with createOrder() method, then at that moment save the order-object in variable and then use that order-object's ID to call the 'cancel_order' by 'id'. that might be easy solution in your case. that is preferred over 'cancel_all_orders' typically. ( btw, sorry, I wanted to type False in my first comment, instead of True however, if you still need this last endpoint to use, i'll try to figure it out, if that's possible and provide the script sample by tomorrow per your explanation. but if cancel_order will be better fit for you, then no need to use cancel_all_orders. ) let me know your thoughts.

You suggested way helps a lot but I would like to see if cancel_all_orders() can work as well so I do not have to bother to manipulate the id if that does not require you a massive load of work to check it out.. thanks!

  • OS: Win10
  • Programming Language version: Python 3
  • CCXT version: Latest

In FTX,

I am able to cancel all conditional trade with the following code:

exchange.cancel_all_orders(symbol,params={'conditionalOrdersOnly': False})

But is it possible to cancel all STOP order instead of both STOP and TAKE PROFIT and TRAILING STOP order? or the only way is to use the cancel_order() function together with the order ID argument?

Hello, Could you tell me how to create TRAILING STOP with ccxt?

PUVl avatar Nov 05 '23 03:11 PUVl