Auto square off at 15:20

tahseen
Dear Support,
If I am having a bracket order and I don't square it off programmatically and it get squared of by RMS at 15:20 is it that a charge of Rs 40 per trade is charged ?

If there is a charge of Rs 40 in case of auto square off then it makes sense to code the auto square off programmatically to close all trades before 15:20
  • sujith
    Hi,
    You can check out Bulletin for details about Call N Trade charges for admin square-off of intra-day positions.
  • tahseen
    @sujith is there a way to square off all standing trades at market price in the python client ?
  • sujith
    You can loop through positions and place a market order for each open position.
  • tahseen
    @sujith

    You mean use this

    order_modify(

    self, order_id, parent_order_id=None, exchange=None, tradingsymbol=None, transaction_type=None, quantity=None, price=None, order_type=None, product=None, trigger_price=0, validity='DAY', disclosed_quantity=0, variety='regular')


    And because I place only bracket orders, what fields would be mandatory for making bracket order as market order ?

    parent_order_id
    order_type

    ?
  • sujith
    You can check out example to exit bracket order.
  • tahseen
    @sujith

    Sorry am using Python not Java. If you can point me to Python module
  • sujith
    The params to be sent remain same and you can use this method.
  • tahseen
    @sujith

    So please confirm below

    1. The bracket order is placed
    2. The bracket order (buy or sell) is executed and trigger and target pending
    3. order_cancel is run passing variety="bo" and parent_order_id of bracket order and this would square off the bracket order at market price

    to use like this?

    kite.order_cancel(variety="bo", parent_order_id="VALUE")
  • sujith
    Yes, you are right. One order will be canceled and the other will be executed at market price.
  • tahseen
    @sujith
    One last question. So not only will this cancel orders that are executed and standing for StopLoss or Target

    But will also cancel bracket orders that were never executed because their limit order was never executed and therefore don't have SL and TP order
  • tahseen
    @sujith
    Got this error when using just variety and parent_order_id

    TypeError: order_cancel() takes at least 2 arguments (3 given)
  • sujith
    When you are canceling first leg order, you need to send it as order_id and not as parent_order_id.
  • tahseen
    So like I pulled orders and I had for example this

    order_id, parent_order_id
    171207000447158, 171207000433530
    171207000447159, 171207000433530

    What should have been the way to cancel it ?
  • sujith
    It can be like kite.order_cancel("171207000447158" , "bo", "171207000433530") to exit after first leg is executed.

    If the first leg is not executed then you can cancel like this kite.order_cancel("171207000433530" , "bo")
  • tahseen
    It didn't work and I got error
  • sujith
    Can you let us know what is the error message?
  • tahseen
    tahseen edited December 2017
    OrderException: Please select a valid BO Order to Exit

    Below is the code. Tabbing was not working so I used underscore here to show tab space

    orders = kite.orders()
    for order in orders:
    ____try:
    ________kite.order_cancel(str(l['order_id']), variety="bo")
    ____except:
    ________kite.order_cancel(str(l['order_id']), variety="bo", parent_order_id=str(l['parent_order_id']))

  • sujith
    I think the order was already canceled. Hence you got the error. This error is from OMS.
  • tahseen
    Doesn't kite.order_cancel return a response instead of error ? If it returns a response, I can use it to continue else I would have to use double try/except because of this
  • tahseen
    you pointed me to that document. I will copy paste the information here and tell me if it is correct

    # Exit / cancel a bracket order.
    import requests
    response = requests.delete("https://api.kite.trade/orders/regular/151220000000000?api_key=xxx&access_token=yyy")

    I think the URL is wrong. Is it this route /regular or /bo
    also it doesn't mention parent_order_id, which is mentioned that it is required in bracket order

    I mean how can I get the correct way to cancel the order at 15:00 hours programmatically
  • tahseen
    tahseen edited December 2017
    @sujith

    So it is only working like this

    kite.order_cancel(order_id=order['order_id'], variety="regular", parent_order_id=order['parent_order_id'])

    in API also valid route is just /regular

    But note it is not exiting the executed order. It is just canceling the Target and SL.

    Now my executed Buy is standing in positions dashboard and I don't know how to square it off. Even i I click exit on it on web UI, now it is taking me to the Order's tab, canceled trade

    Means order_cancel is actually just canceling the trigger and target. It is not exiting my buy and sell positions standing in Positions Tab

    What is this ?
  • tonystark
    When you cancel a BO order you have to send the variety as "bo".

    If you are using our API directly you can find the example in documentation directly below the one you posted:

    # Exit / cancel a bracket order.
    curl --request DELETE \
    "https://api.kite.trade/orders/bo/151220000000000?api_key=xxx&access_token=yyy&parent_order_id=151210000000000"
  • tahseen
    tahseen edited December 2017
    @tonystark route /bo doesn't exit was the message that I got. Are you sure /bo exists ? Please check for xxx154 cancel requests that came for /bo route and got an error response
  • tonystark
    Can you post full request and response dump here?
  • tahseen
    tahseen edited December 2017
    @tonystark
    @sujith
    @Pushwinder

    Before that let me put things clearly

    IOC SELL Bracket Order executed

    Now standing SL and TP as below

    name, order_id, parent_order_id
    IOC 171211000832542 171211000832538 OPEN
    IOC 171211000832543 171211000832538 TRIGGER PENDING

    I want to square off the trade at market to get out of it

    Please give URLs made for these. Note there are two order_id - one for TP and one for SL and have same parent_order_id
  • sujith
    For canceling a bracket order, you need to do something like this,
    curl --request DELETE \
    "https://api.kite.trade/orders/bo/171211000832542?api_key=xxx&access_token=yyy&parent_order_id= 171211000832538"

    When you send the above request the system will take care of canceling one order and modifying the other to market which will result in closing the position.

    If you cancel order like this,
    curl --request DELETE \
    "https://api.kite.trade/orders/regular/171211000832542?api_key=xxx&access_token=yyy

    then you are canceling this order as normal order and at the end, you will end up canceling both second orders and your position will remain open.

    In the above scenario when an open position exists, you need to place a market MIS order of opposite transaction type and inform our RMS about it so that there won't be confusion while doing MIS square off.
  • tahseen
    tahseen edited December 2017
    @sujith
    Finally, this worked

    "https://api.kite.trade/orders/bo/171211000832542?api_key=xxx&access_token=yyy&parent_order_id= 171211000832538"

    Means I need to only pass TP order_id and parent_order_id


    Ok about now closing the positions that are open. If I now take reverse MIS position of equal quantity for all positions that are exiting, will that cancel the position ?

    Also where should I write to RMS ? Time is less and I need to email them quickly to avoid 3:20pm open position penalty
  • sujith
    You need to call support and speak to someone from RMS.
    This time, we have informed RMS and they will take care of it.
    Just for confirmation, Can you name the tradingsymbol for which this issue has happened?
  • tahseen
    @sujith

    Thanks

    Stocks are below. I have taken reverse quantity position
    ADANIPOWER
    IFCI
    MARICO
    PVR
    RCOM
This discussion has been closed.