Checking hour and minute

Course Name: Automated Trading with IBridgePy using Interactive Brokers Platform, Section No: 7, Unit No: 5, Unit type: Exercise



I understand we trade Mon-Fri only BUT I don't understand why in next line of code we check again hour and minute. Can't we just trade all day long?

thanks

Hi Gian,



The handle_data function runs every second. The check we do in the if statement is sTime.hour==dt.datetime.now().hour and sTime.minute==dt.datetime.now().minute. This is always true. So in effect we are setting context.flag to False every second and then checking the crossover.



This code will run every second (the same as handle_data).



The purpose is to keep continuity of the code structure as you learnt in Section 7, unit 1 where the if-else block was used to perform trade operations at the end of market hours.



Hope this helps!