STOP_LOSS and TAKE_PROFIT orders via Python API

Hi there, so i usually go for STOP_LOSS_LIMIT orders (type = “STOP_LOSS_LIMIT”), i’m not sure how to set up just “STOP_LOSS” or “TAKE_PROFIT” orders and how they work, i’ve read the documentation but there’s no examples, it’s supposed to trigger market order price (sell = STOP_LOSS, buy = TAKE_PROFIT) when the price hits the “stopPrice” parameter amount, but as i can also see in the docs you can’t set a time in force so price would vary depending on order book stock right? please tell me if i’m wrong, so an example would be:

client.create_order(
symbol = “BTCBUSD”,
side = “SELL”, # Is this needed???
type = “STOP_LOSS”, # or “TAKE_PROFIT”
quantity = quantity,
price = str_formato_decimal.format(limit_price),
stopPrice = str_formato_decimal.format(stop_price),
)

Is the side needed for those also? because STOP_LOSS is supposed to always sell and TAKE_PROFIT to BUY? i’m really confused about that sorry… AND THANKS!

  • Both SELL and BUY orders can have STOP_LOSS or TAKE_PROFIT, so you need to send param “side” along with the “type”:
    If you’re selling, you want to STOP_LOSS when the price is going down and TAKE_PROFIT when the price is going up.
    Contrary logic applies for when you’re buying.

  • STOP_LOSS and TAKE_PROFIT are market orders, so no need to send param “price” as those orders will be executed with the market price when the stopPrice is triggered;