Skip to content

Instantly share code, notes, and snippets.

@ganigithub
Created June 21, 2022 15:18
Show Gist options
  • Save ganigithub/034aa5bde75fb59e462ced7dd609dae1 to your computer and use it in GitHub Desktop.
Save ganigithub/034aa5bde75fb59e462ced7dd609dae1 to your computer and use it in GitHub Desktop.
########################## EXIT CONDITION #########################
for i in range(1000000):
try:
t = datetime.datetime.now()
ltp = kite.ltp(ticker_symbol)[ticker_symbol]['last_price']
print('ltp :', ltp)
if (ltp >= target):
order(trading_symbol, "SELL", quantity, kite)
print(f'Target breached. Sold at Rs.{ltp}, PROFIT')
break
elif (ltp <= stop_loss):
order(trading_symbol, "SELL", quantity, kite)
print(f'stoploss breached. Sold at Rs.{ltp}, LOSS')
break
elif (t.hour == exit_hour) and (t.minute == exit_minute):
order(trading_symbol, "SELL", quantity, kite)
print(f'Trade Exit : No breach. Sold at Rs.{ltp}')
break
except BaseException as error:
print(f'{error} Exception occurred.')
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment