Unable to modify my cover order stop loss orders using kite python api

srinu124
I am unable to modify my stop loss orders for the cover orders using kite api. it was working fine till yesterday. i am getting exception now.
Tagged:
  • rakeshr
    Can you paste the complete exception message here?
  • srinu124

    getting input exception
  • srinu124
    new_price = float(pric)
    kite.modify_order(order_id=order_id,variety=kite.VARIETY_CO,parent_order_id=parent_order_id, \
    quantity=int(pending_quantity), price=0, order_type=order_type, trigger_price=new_price,\
    validity='DAY', disclosed_quantity=int(pending_quantity))


  • srinu124
    it was working fine 2 days back
  • sujith
    You need to run pykiteconnect with debug flag and paste the exception message here.
  • srinu124
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "PUT /orders/co/211203201477596 HTTP/1.1" 400 362
    [Fri, 03 Dec 2021 14:31:06] [Exception in Display & Modify Cover Orders ]
    INFO:root:Exception in Display & Modify Cover Orders
  • sujith
    You need to enable debug log here and paste the json response.
  • srinu124
    I am unable to do it. it was working fine for many months . Dont know why its not working now. atleast give me a sample code for how to change stop loss for cover orders
  • srinu124
    is this fine?
    kite.modify_order(order_id=order_id,variety=variety=kite.VARIETY_CO,parent_order_id=parent_order_id,\
    quantity=int(pending_quantity), price=0, order_type=order_type, trigger_price=new_price,\
    validity='DAY', disclosed_quantity=int(pending_quantity))
  • sujith
    What is the status message of that order in the orderbook after sending this request?
  • srinu124
    the script fails with exception, input exception

    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "PUT /orders/co/211206100608902 HTTP/1.1" 400 362
    [Mon, 06 Dec 2021 10:08:33] [Exception in Display & Modify Cover Orders ]
    INFO:root:Exception in Display & Modify Cover Orders
  • srinu124
    Please give me sample python code on how to change the stop loss market order for cover orders
  • sujith
    You need to enable debug log here.
    You can paste the exception json here.
  • srinu124
    Could you Please give me sample python code on how to change the stop loss market order for cover orders
  • erutkarshh
    erutkarshh edited December 2021
    I'm also facing same problem - I'm trying to update SL-M (2nd leg) order of Cover Order. 2nd leg order is of BUY Type, where I'm changing trigger price to 460.45 and it is asking me to put a price lower than LTP, which is not making any sense to me as SL trigger price for SELL order should be more than LTP.

    Error: Stoploss trigger price for the sell (exit) leg of the Cover order (CO) should be lower than the last traded price (457.2). [Read more.](https://support.zerodha.com/category/trading-and-markets/margin-leverage-and-product-and-order-types/articles/what-are-cover-orders-and-how-to-use-them)

    Code:
    order_id = self.kite.modify_order(
    order_id='211206002218991',
    variety=self.kite.VARIETY_CO,
    order_type=self.kite.ORDER_TYPE_SLM,
    price=None,
    trigger_price=461.45
    )

    I'm able to modify this order from Kite App. Please help.

    Attached is screenshot of another order. How such order looks when I'm trying to modify from code.

  • rakeshr
    Can you check, if you are using correct order_id not first leg order_id?
    This thread explains more.
  • srinu124
    Rakeshr/Sujith,
    I am using correct order_id and everything was working perfectly fine from more than an year.
    Please i am requesting you guys again to give some sample code instead of asking to try something & pointing to some irrelevant links. please give me some solution?

    -> how do we modify the stop loss market order for cover order after its triggered ( for 2nd leg)
    -> Do we need to give the parent order id also or not?
    -> is the below snippet correct or not??

    kite.modify_order(order_id=order_id,variety=variety=kite.VARIETY_CO,parent_order_id=parent_order_id,\
    quantity=int(pending_quantity), price=0, order_type=order_type, trigger_price=new_price,\
    validity='DAY', disclosed_quantity=int(pending_quantity))
  • erutkarshh
    @rakeshr, @sujith Yes. I'm using 2nd leg order id only. You can try yourself as well. My subscription is going to end in 4 days. Renewal depends on resolution of this thread. There is no point in wasting money. Please help.
  • srinu124
    Please give sample code.. Plsssss
  • srinu124
    Here is the issue ,

    For trigger pending buy orders API is expecting the price should be lesser than LTP ( instead of higher value). and when i give less price its accepting and executing but in the orders i see error message.

    Its clearly api issue.

    kiteconnect.exceptions.InputException: Stoploss trigger price for the sell (exit) leg of the Cover order (CO) should be lower than the last traded price (1676.05). [Read more.](https://support.zerodha.com/category/trading-and-markets/margin-leverage-and-product-and-order-types/articles/what-are-cover-orders-and-how-to-use-them)
  • srinu124
    >>> kite.modify_order(order_id="211207201331813",variety=kite.VARIETY_CO,quantity=25,price=0, order_type=kite.ORDER_TYPE_LIMIT, trigger_price=1682.4,validity='DAY')
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "PUT /orders/co/211207201331813 HTTP/1.1" 400 363
    Traceback (most recent call last):
    File "", line 1, in
    kite.modify_order(order_id="211207201331813",variety=kite.VARIETY_CO,quantity=25,price=0, order_type=kite.ORDER_TYPE_LIMIT, trigger_price=1682.4,validity='DAY')
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/kiteconnect/connect.py", line 371, in modify_order
    return self._put("order.modify",
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/kiteconnect/connect.py", line 830, in _put
    return self._request(route, "PUT", url_args=url_args, params=params, is_json=is_json)
    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/kiteconnect/connect.py", line 894, in _request
    raise exp(data["message"], code=r.status_code)
    kiteconnect.exceptions.InputException: Stoploss trigger price for the sell (exit) leg of the Cover order (CO) should be lower than the last traded price (1676.05). [Read more.](https://support.zerodha.com/category/trading-and-markets/margin-leverage-and-product-and-order-types/articles/what-are-cover-orders-and-how-to-use-them)
  • sujith
    @srinu124,
    There is no issue with the code. This is something else. Are you modifying second leg or first leg order?

    Why are you sending order type as LIMIT if it is second leg order?
  • srinu124
    its second leg order. means, i placed the cover order which got triggered and now trying to modify the stop loss for the trigger pending order.

    I tried with "order_type=kite.ORDER_TYPE_SLM" also but still same issue.
  • srinu124
    I saw the issue manually also sometimes while changing stop loss. it shows error saying trigger price should be lower than LTP . some issue from ur side. could you please help soon. its really blocking me
  • sujith
    sujith edited December 2021
    It looks like the modify request was sent with trigger price 1672.4, since for BUY stoploss the value should be greater than LTP, modify request is rejected.
    I think the price was around 1676 at the time you sent the request.
  • srinu124
    Oh God. . I sent with 1682.4 and not 1672.4 .
    And i am using these APIs from many months. and i know how to use them.
    And there is no issue with inputs and i tried all combinations.

    Please look into the issue seriously and give some resolution.
  • erutkarshh
    @sujith Buddy, I have shared a screenshot with you. SL price failed from API but worked from UI. At that time the difference in SL that I tried putting was around 5%. I'm sure the price was not moving 5% up-down within seconds. :#
  • rakeshr
    @erutkarshh @srinu124
    We are checking on this.
  • srinu124
    any update?
Sign In or Register to comment.