how to find out opposite transaction type of a open position using python

abhijit
To exit from a order, we need to use exit_order(varaiety,order_id). But if we have multiple orders for a day, how to distinguish orders that needs to be execute.
  • rakeshr
    You need to check the quantity field from the fetch position. If it's negative then it is a short position else it is a long position. Quantity with zero is a closed position.
  • abhijit
    Hi Rakesh, thanks for replying. I understand that from the fetch position we can know the open position. But my question is how to know the equivalent order id, so that we can exit the trade.

    For example, suppose I have buy a stock in SBIN at 10:00 AM and successfully exit at 10:30 AM. Again at 11:00 AM I purchased SBIN and at 11:30 I want to exit the position. Then at that time we have two orders related to SBIN one is for 10:00 AM call and another is for 11:00 AM call. As the open position won't holds and order id related to the particular order it is difficult to choose the correct order id using Python?

    Hope I am able to explain you the scenario. For now whenever I am calling for orders related to trading symbol (i.e:SBIN), it is giving me two order id one for 10:00 AM and other for 11:00 AM, because both are for same trading symbol(i.e:SBIN). But here I am not able to find out how to differentiate both. Because as the 10:00 AM order id already executed, it is giving error to me when I am using loop to execute exit orders by passing the order id.

    If it is possible for you to give me the python code for exit an order, it will be helpful.

    Thanks in advance.
  • sujith
    I think you should use Kite web or app first to understand the concept. Positions is a mark to market view of the account, it is not related to orderbook.
    Orderbook contains the list of orders placed by the user and it shows the status of the order and its details.
  • SRIJAN
    SRIJAN edited October 2021
    @abhijit Just use the latest order id to exit because that will be the position which has not been closed. Means fetch all orders for sbi and put [-1] .
  • SRIJAN
    SRIJAN edited October 2021
    ❤️
  • abhijit
    Thanks Srijan
Sign In or Register to comment.