Replace condition to check for successful connection to IBKR with assertion

This commit is contained in:
moshferatu 2024-03-03 05:35:42 -08:00
parent 84df97d96b
commit 8a0355cc98

View File

@ -28,14 +28,12 @@ def connection_successful():
return False
if __name__ == '__main__':
now = datetime.now(timezone(eastern_timezone))
assert connection_successful(), 'Cannot connect to IBKR. Ensure that TWS or Gateway is running.'
now = datetime.now(timezone(eastern_timezone))
if all(filter.trade_allowed(now) for filter in trade_filters):
print('Trade filters allow for trading today.')
if connection_successful():
print('Connected to IBKR.')
entry_times = getenv('ENTRY_TIMES').split(',')
for entry_time in entry_times:
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
@ -53,7 +51,5 @@ if __name__ == '__main__':
while True:
schedule.run_pending()
time.sleep(1)
else:
print('ERROR: Cannot connect to IBKR. Ensure that TWS / Gateway is running.')
else:
print('Trade filters prevent trading today.')