Exit position using SmartAPI?
-
Hello Team SmartAPI! I've been working on this algo from last 5-6 months and I came across this issue regarding the exiting position/s in SmartAPI. Is there any way to exit the open position through code? I have gone through docs and they didn't mentioned it. Also I have checked some of previous discussions regarding this issues, so is there any update on that? Please let me know is there any way to do this. Thank you.
-
@usrikanth hello there! Thank you for your help and code you provided. I've been looking for it since 8 months now and each time it failed. I'll try with this code you provided and tell you further. Thanks again.
-
@aniket I just started using the api recently, and this is what I do. To exit a position, I just create the 'transaction type' of the exit order based on whether 'qty' value in my position is +ve or -ve. The piece of code in my system that does this. Hope this helps.
def createExitOrders(self): orders = [] for leg in self.position: orders.append((leg['symbol'], leg['symboltoken'], abs(leg['qty']), 'buy' if leg['qty'] < 0 else 'sell')) return orders
-
@Moderator_3 hello again! i have tried replacing order type from buy to sell but it is directly selling instead of exiting position. If you can provide little code snippet about exit position or selling it in right way, it would be helpful. Thanks again. Waiting for your response.
-