Automation GTT

theankitdabas
for automation of placing two legg GTT order, and regular updating it through a trailing script.... do we need to use Socket or how it can be done ?
Tagged:
  • rajnivp
    for trailing you'll need to keep monitoring live price so for that you need to use websocket connection
  • theankitdabas
    HOW TO GET THIS DONE ??

    def on_order_update(self, ws, data)
    # Handle order updates
    # TODO: Here we need to add code to place the order

    in this section i want to get the order id of each BUY order placed and place a SELL two leg gtt order with stoploss -27% and target 12%
  • mangroliyahilesh
    Any update?

    It seems very poor support from zerodha. I am trying this since 2 months and not able to solve it. No one connecting directly and not supporting quickly on post also.
  • sujith
    We don't provide any support or solution for writing strategies. There are documentation and examples for all the APIs and the client libraries. You can refer to the same.
  • mangroliyahilesh
    @sujith Not asking for writing strategies. Need to have correct information to close position using gtt order api. As far as I checked all forum answers, it says we need to add opposite order. When I add it, and it triggers, it says insufficient fund. why it would required to have fund as my buy position for NFO is already there.

    Neither I am not able to find on doc. Can you share doc link where it specifies that exiting option buy, we need to do this?
  • mangroliyahilesh


    I tried Normal and MIS order both. Screenshot is attached for MIS get order.

    As per doc: https://kite.trade/docs/connect/v3/orders/

    MIS : Margin Intraday Squareoff for futures and options ?
  • sujith
    Are you using the same product type as the existing position? Can you private message the order id for which you have this issue, it is better if you have logs of current day. The order history gets erased after BOD.
  • mangroliyahilesh
    I have opened order with below code:

    kite.place_order(
    variety=kite.VARIETY_REGULAR,
    exchange=kite.EXCHANGE_NFO,
    tradingsymbol=trading_symbol,
    transaction_type=kite.TRANSACTION_TYPE_BUY,
    quantity=quantity,
    product=kite.PRODUCT_NRML,
    order_type=kite.ORDER_TYPE_LIMIT,
    price=price,
    tag=f""
    )

    It opens order or Zerodha and at limit price, it executes.
    Now I need to close/exit this position with GTT order by setting Stop Loss and Take Profit.
    I have used below code for that:

    order_dict = [{"transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_MIS,
    "price": loss},
    {"transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_MIS,
    "price": target}]
    kite.place_gtt(kite.GTT_TYPE_OCO, trading_symbol, kite.EXCHANGE_NFO,
    [loss, target],
    ltp, order_dict)

    This is also creating GTT order but at execution time, it says insufficient fund.
    I am closing/exiting position with inverse order as sell of my existing buy with type as MIS for normal option buy order.
    Let me what should be used to close/exit position to close/exit my existing position with OCO GTT.
  • mangroliyahilesh
    @sujith Can you please help with required information?
  • sujith
    It is because you are using MIS as the product type while placing GTT. It should be of same product type as the open position.
  • mangroliyahilesh
    @sujith That is also not working. I tried that first too. As mentioned that before.
  • mangroliyahilesh
    Any update?
  • rakeshr
    order_dict = [{"transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_MIS,
    "price": loss},
    {"transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity,
    'order_type': kite.ORDER_TYPE_LIMIT, "product": kite.PRODUCT_MIS,
    "price": target}]
    As @sujith mentioned you need to use same product type as used to create the position i.e here NRML. Make sure, the quantity is matching as per the open quantity.
  • mangroliyahilesh
    @rakeshr I already mentioned that with same type is also not working. I tried that first.
Sign In or Register to comment.