Replace condition to check for successful connection to IBKR with assertion
This commit is contained in:
parent
84df97d96b
commit
8a0355cc98
@ -28,14 +28,12 @@ def connection_successful():
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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):
|
if all(filter.trade_allowed(now) for filter in trade_filters):
|
||||||
print('Trade filters allow for trading today.')
|
print('Trade filters allow for trading today.')
|
||||||
|
|
||||||
if connection_successful():
|
|
||||||
print('Connected to IBKR.')
|
|
||||||
|
|
||||||
entry_times = getenv('ENTRY_TIMES').split(',')
|
entry_times = getenv('ENTRY_TIMES').split(',')
|
||||||
for entry_time in entry_times:
|
for entry_time in entry_times:
|
||||||
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
|
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
|
||||||
@ -53,7 +51,5 @@ if __name__ == '__main__':
|
|||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
|
||||||
print('ERROR: Cannot connect to IBKR. Ensure that TWS / Gateway is running.')
|
|
||||||
else:
|
else:
|
||||||
print('Trade filters prevent trading today.')
|
print('Trade filters prevent trading today.')
|
Loading…
Reference in New Issue
Block a user