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;

Hi! I’m trying making a STOP_LOSS_LIMIT call, but I got error 400 bad request.
I can do a normal MARKET order, but when I change the type with STOP_LOSS_LIMIT (same thing for the STOP_LOSS), I got the error 400.
Could you please help me?
I’m using php, and composing the parameters this way:
$params = [
‘symbol’ => $symbol, //which has the STOP_LOSS_LIMIT option in the api/v3/exchangeInfo
‘side’ => ‘BUY’,
‘type’ => ‘STOP_LOSS_LIMIT’,
‘quantity’ => (float) number_format($cryptoQuantity, 2),
‘stopPrice’ => (float) number_format($stopLossPrice, 2),
‘timestamp’ => time() * 1000
];
after I correctly add the signature so it’s not an authentication problem.
thank you!