How to cancel all open trades?

kreakemp
I want to square off all open trade at the same time, how this can be done in Node Js. I can get the positions details but don't getting the order is, in open trade/positions details. To cancel the trade order_id is necessary?
  • rakeshr
    @kreakemp
    To close the open position, you can place fresh counter order for all those open positions in loop.For eg.If you have 1 lot of Banknifty July contract, from positions details, you can fetch contract detail and order type(long/short) and place opposite transaction type(Here eg, place sell order for 1 lot Banknifty contract).
    For all open orders under order book, you can fetch complete order book details(which includes order_id), and cancel those order using order_id.
  • kreakemp
    kreakemp edited July 2019
    @rakeshr
    Thanks for your solution. It will work with MIS orders but what about BO orders. There the order is placed with LIMIT, so even if I am taking the LTP, there is a chance that my order will not be executed.. in case of BO order how to ensure the same.
  • rishiswethan
    rishiswethan edited July 2019
    https://pastebin.com/iRP1r86P

    This is a very simple function to cancel all orders. This is in python, but, you can refer this to make it in node js too
  • kreakemp
    Thanks @rishiswethan I will check the same.

    @rakeshr I got the solution, I can place LIMIT order with lower/higher as per SELL/BUY order so that it will be executed immediately.

Sign In or Register to comment.