Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Exit position using SmartAPI?

    Python SDK
    0
    5
    79
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aniket last edited by

      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.

      M 1 Reply Last reply Reply Quote 0
      • M
        Moderator_3 @aniket last edited by

        Hello @aniket

        Please use the place order API to achieve the same

        Regards,
        SmartAPI Team

        A 1 Reply Last reply Reply Quote 0
        • A
          aniket @Moderator_3 last edited by

          @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.

          U 1 Reply Last reply Reply Quote 0
          • U
            usrikanth @aniket last edited by

            @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
            
            A 1 Reply Last reply Reply Quote 0
            • A
              aniket @usrikanth last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post