Shoonya-Dev / ShoonyaApi-py

139 stars 130 forks source link

Close all Open Position API #97

Closed sanind closed 3 months ago

sanind commented 1 year ago

Do we have API to close all open positions?

Say I ordered

  1. Buy SBILIFE-EQ quantity =10
  2. Buy SBILIFE-EQ quantity =20
  3. Sell INFY-EQ quantity = -10

Now I want to close all open positions...

pydev369 commented 1 year ago

From Orderbook & Positions api call it can be done....In python its simple, Do u need a demo ?

TWP80 commented 5 months ago
def exit_all_positions():
    position_dict = api.get_positions() or []
    for position in position_dict:
        api.place_order(
            buy_or_sell="S" if int(position["netqty"]) > 0 else "B",
            product_type=position["prarr"],
            exchange=position["exch"],
            tradingsymbol=position["tsym"],
            quantity=position["netqty"],
            discloseqty=position["netqty"],
            price_type="MKT",
            retention="DAY",
            remarks="my_order_001",)
Shoonya-Dev commented 3 months ago

Greetings from Shoonya!

Please refer to the below-attached link for closing the positions:

https://github.com/Shoonya-Dev/ShoonyaApi-py/blob/master/README.md#md-place_order