How to set Algo with auto Start and Stop at a specific timestamp.

D11458
@rakeshr @sujith - Hello, how can we set a timer to Algo program, ie it can start once a specified time condition meets and stops same way?
Below a part of the code. It doesn't work, I noticed the program keeps running after exit time condition. Can someone assist what is needed to solve this issue?

while True:

now = datetime.datetime.now()
if (now.hour >= 13 and now.minute >= 10 ):
kws.on_ticks=on_ticks
kws.on_connect=on_connect
kws.connect()
if (now.hour >= 14 and now.minute >= 00):
sys.exit()
  • SITPL
    you need to set the exit condition inside on_ticks as code after kws.connect will not execute
  • rjamitsharma
    started=False

    while True:

    now = datetime.datetime.now()
    if (now.hour >= 13 and now.minute >= 10 and started ==False ):
    kws.on_ticks=on_ticks
    kws.on_connect=on_connect
    kws.connect(threaded=True)
    started=True
    elif (now.hour >= 14 and now.minute >= 00):
    sys.exit()


    This code might work for you
  • D11458
    Thanks @rjamitsharma - will give it a go and see the result! appreciate it..
Sign In or Register to comment.