stock updates only in NY stock exchange hours

This commit is contained in:
Neythen Treloar 2022-03-06 10:04:03 +00:00
parent 4948d6564a
commit 5cf29c80e4
2 changed files with 9 additions and 3 deletions

View File

@ -658,7 +658,13 @@ if __name__ == '__main__':
stock_time = datetime.strptime(last_updates['stocks']['time'], "%d/%m/%Y %H:%M:%S")
stock_frequency = update_frequencies['stocks']
diff = (NY_time - stock_time).total_seconds()/60 #minutes
if last_updates['stocks']['force'] or diff >= update_frequencies['stocks']:# or msg == 's':
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
opening = NY_time.replace(hour=9, minute=30, second=0, microsecond=0).replace(tzinfo=None)
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None)
stock_open = opening < NY_time < closing and datetime.today().weekday() <= 4
if last_updates['stocks']['force'] or (diff >= update_frequencies['stocks'] and stock_open):# or msg == 's':
stock_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
last_updates['stocks']['time'] = stock_time
last_updates['stocks']['force'] = False
@ -762,7 +768,7 @@ if __name__ == '__main__':
process.join()
process.terminate()
update_processes.remove(process)
print('Number active processes', len(update_processes))
print('Number active database caller processes', len(update_processes))
time.sleep(10)

View File

@ -2754,7 +2754,7 @@ if __name__ == '__main__':
#stock_ticker.process_msg('*')
#time.sleep(8)
stock_ticker.process_msg('-')
#stock_ticker.process_msg('-')
#stock_ticker.process_msg('W')
#stock_ticker.process_msg('A')