rishiswethan2

Exit all positions

Jul 18th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. def sell_all(minute=99, second=99, variety='regular', product_to_use='ALL'):
  2.     while ((util.getTime()['min'] != minute) or (util.getTime()['sec'] != second)) \
  3.             and ((second != 99) and (minute != 99)):
  4.         time.sleep(0.01)
  5.  
  6.     holdings = kite.positions()
  7.     print(holdings)
  8.     # return
  9.     for x in holdings['net']:
  10.         res = x
  11.         quantity = res["quantity"]
  12.         exchange = res["exchange"]
  13.         symbol_name = res["tradingsymbol"]
  14.         product = res["product"]
  15.         # print(product)
  16.         # print(res)
  17.         if (product_to_use != 'ALL') and (product_to_use != product):
  18.             continue
  19.  
  20.         print('\n')
  21.         if quantity < 0 and product == 'MIS':
  22.             # print(res, '\n\n')
  23.             quantity = buy_stocks[res['tradingsymbol'] + '+' + res['exchange']][0]
  24.             print(quantity, exchange, symbol_name, product, variety)
  25.             print('Selling ' + str(quantity) + ' ' + symbol_name)
  26.             print()
  27.             # if False:
  28.             """Place Sell Market Order"""
  29.             # get_margin_cap_available()
  30.             if config.deploy:
  31.                 order_id1 = kite.place_order(variety=variety, exchange=exchange,
  32.                                              tradingsymbol=symbol_name,
  33.                                              transaction_type="SELL", quantity=abs(quantity),
  34.                                              product=product,
  35.                                              order_type="MARKET",
  36.                                              price=None, validity="DAY", disclosed_quantity=None,
  37.                                              trigger_price=None,
  38.                                              squareoff=None,
  39.                                              stoploss=None,
  40.                                              trailing_stoploss=None,
  41.                                              tag=None)
  42.  
  43.     print("SOLD!")
Add Comment
Please, Sign In to add comment