Check if position is open or closed

llpach
Hi,
I want to check if position is closed or open using java api then accordingly cancel my another order. What is the method to check this?
  • sujith
    Hi @llpach,
    A closed position will have netQuantity = 0.
    Can you elaborate on your scenario so that we can give more specific answer?
  • llpach
    Hi @sujith ,
    I have a scenario like,
    1) Placed 2 different orders at price x with y target
    2) Both orders are executed. Now, i want to check if any one out these positions is closed then i want to close other position too.
    So how can i check if position is open or closed
  • sujith
    Hi @llpach,
    Once you place an order you get order_id after the request is successful.
    Fetch orderbook and check the status of both orders, if the status of one of the orders is rejected then fetch positions, find the corresponding position which will have the same tradingsymbol and product and then place a market order with opposite transaction_type.

    PS: If an order is rejected then there won't be an entry in positions table.
  • llpach
    My orders are bracket order, so in case of bracket order, market order is not possible right? then how would i exit my bracket order, please help.
  • sujith
    Hi @llpach,
    You can find the order with parent order id same as the id what you get after placing an order.
    Once you get second leg orders, you can cancel one of the child order like this.
This discussion has been closed.