how to place SL in python code

ashuthinks
this is my current code to place order

order_id = kite.place_order(tradingsymbol="BANKNIFTY20OCTFUT",
exchange=kite.EXCHANGE_NFO,
transaction_type=kite.TRANSACTION_TYPE_SELL,
quantity= 25,
order_type=kite.ORDER_TYPE_MARKET,
product=kite.PRODUCT_MIS,
variety = kite.VARIETY_REGULAR)

I want to add Stoploss also which is 50 points down market price how to add this any help ?
  • sujith
    You need to select the order type as SL and send the trigger price. The trigger price has to be sent as (last price - 50) in your case.
  • ashuthinks
    but i need a trigger price as market price is there anything we can do for?
  • sujith
    You can enter the last price as trigger price, that is not an issue.
  • sujith
    You can read more about SL here.
  • ashuthinks
    ashuthinks edited October 2020
    you mean something like this is correct , can any python developer help me . im new in python.
    order_id = kite.place_order(tradingsymbol="BANKNIFTY20OCTFUT",
    exchange=kite.EXCHANGE_NFO,
    transaction_type=kite.TRANSACTION_TYPE_BUY,
    quantity=tradeQuantity,
    order_type=kite.ORDER_TYPE_SL,
    product=kite.PRODUCT_MIS,
    trigger_price= kite.ltp()-50,
    variety = kite.VARIETY_REGULAR)

    ohh you mean need to write seperate code for SL , is there any way to do it in single code?
  • rakeshr
    Yes, the above order param seems fine. You can add validity field as well. Refer to this method to know all order param required for python client.
  • ashuthinks
    stoploss_price = kite.ltp('NSE:TATASTEEL')['NSE:TATASTEEL']['last_price'] - 50

    kite.place_order(tradingsymbol="TATASTEEL",
    exchange=kite.EXCHANGE_NSE,
    transaction_type=kite.TRANSACTION_TYPE_SELL,
    quantity=1,
    trigger_price=stoploss_price,
    price=stoploss_price,
    order_type=kite.ORDER_TYPE_SL,
    product=kite.PRODUCT_MIS,
    variety = kite.VARIETY_REGULAR
    )

    this works for me but creates 3 SL orders why ?
  • rakeshr
    Are you placing an order inside the loop?
  • ashuthinks
    ashuthinks edited October 2020
    yes but i think when i used SM it works fine
Sign In or Register to comment.