3

Does anyone have an example of how to create a market order with take profit and stop loss?

I have been through the docs and because this is the first time i've done anything like this I don't really get it!

I'm trying to create an API endpoint that takes an alert from TradingView and places an order. I don't really want to use limit orders because I just want to place the order at the current price.

I have everything working except for actually placing the order!!

I'd appreciate any help on this!

Steve
  • 175
  • 1
  • 3
  • 13

1 Answers1

8

As I couldn't find a solution anywhere in documentations. So, I come up with workaround (this may not the most efficient approach, it works for me though) I have started placing orders using 3 orders in sequence.

Example Scenario: Buy SOL for $300 at Market price (139.00).

#Place Market Buy Order, Buying volume = 2.15 for $300
ftx.create_order('SOL/USD','market','buy',2.15)

#Place Stop-loss order, volume = 2.15 when price reaches 135.00
ftx.create_order('SOL/USD','stop','sell',2.15,params={'triggerPrice':135.00,'reduceOnly': True})

#Place take-profit order, volume = 2.15 when price reaches 148.00
ftx.create_order('SOL/USD','takeProfit','sell',2.15,params={'triggerPrice':148.00,'reduceOnly': True})

make sure to include reduceOnly parameter so as not to open a new position should either of SL/TP order gets executed.

I realized either of TP/SL orders will be left out in order book as one gets filled, I am not sure what happens then so to avoid conflict with new order for same asset. i am handling that separately before placing new orders using -

ftx.cancel_all_orders(symbol, {'conditionalOrdersOnly':True})
VJKR
  • 199
  • 1
  • 9