Replace condition to check for successful connection to IBKR with assertion
This commit is contained in:
parent
84df97d96b
commit
8a0355cc98
@ -28,32 +28,28 @@ 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():
|
entry_times = getenv('ENTRY_TIMES').split(',')
|
||||||
print('Connected to IBKR.')
|
for entry_time in entry_times:
|
||||||
|
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
|
||||||
|
year = now.year,
|
||||||
|
month = now.month,
|
||||||
|
day = now.day,
|
||||||
|
tzinfo = now.tzinfo
|
||||||
|
)
|
||||||
|
|
||||||
entry_times = getenv('ENTRY_TIMES').split(',')
|
# Prevent scheduling for times that have already elapsed.
|
||||||
for entry_time in entry_times:
|
if schedule_time > now:
|
||||||
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
|
print(f'Scheduling for {entry_time}.')
|
||||||
year = now.year,
|
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade, schedule_time)
|
||||||
month = now.month,
|
|
||||||
day = now.day,
|
|
||||||
tzinfo = now.tzinfo
|
|
||||||
)
|
|
||||||
|
|
||||||
# Prevent scheduling for times that have already elapsed.
|
while True:
|
||||||
if schedule_time > now:
|
schedule.run_pending()
|
||||||
print(f'Scheduling for {entry_time}.')
|
time.sleep(1)
|
||||||
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade, schedule_time)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
schedule.run_pending()
|
|
||||||
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