How to square off all positions?

Any ways to square off all positions instead of looping on orders and placing square off for each order?
  • sujith
    sujith edited October 2020
    For regular(MIS, CNC, NRML) positions, you need to loop through positions to square off positions by placing an order of opposite transaction type for the same number of quantities at the market.

    For bo, co positions, you need to loop through orderbook and find the pending orders with parent order id and send an exit position request.
    For bracket order exit, the system will take care of canceling one of the orders and modifying another order to execute at the market.

    You can refer to the documentation here.
  • TUSH123
    it will be helpful if you provide sample code to squareoff each position
  • TUSH123
    dont we have any positionid and orderid which are unrealized?
  • sujith
    For a given tradingsymbol and exchange, there will be only one position of one product type always.
  • sujith
    A closed position will have quantity=0
This discussion has been closed.