Replace trade filter condition with an assertion
This commit is contained in:
parent
8a0355cc98
commit
0bebd31c26
@ -31,25 +31,22 @@ if __name__ == '__main__':
|
|||||||
assert connection_successful(), 'Cannot connect to IBKR. Ensure that TWS or Gateway is running.'
|
assert connection_successful(), 'Cannot connect to IBKR. Ensure that TWS or Gateway is running.'
|
||||||
|
|
||||||
now = datetime.now(timezone(eastern_timezone))
|
now = datetime.now(timezone(eastern_timezone))
|
||||||
if all(filter.trade_allowed(now) for filter in trade_filters):
|
assert all(filter.trade_allowed(now) for filter in trade_filters), 'Trade filters prevent trading today.'
|
||||||
print('Trade filters allow for trading today.')
|
|
||||||
|
|
||||||
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(
|
||||||
year = now.year,
|
year = now.year,
|
||||||
month = now.month,
|
month = now.month,
|
||||||
day = now.day,
|
day = now.day,
|
||||||
tzinfo = now.tzinfo
|
tzinfo = now.tzinfo
|
||||||
)
|
)
|
||||||
|
|
||||||
# Prevent scheduling for times that have already elapsed.
|
# Prevent scheduling for times that have already elapsed.
|
||||||
if schedule_time > now:
|
if schedule_time > now:
|
||||||
print(f'Scheduling for {entry_time}.')
|
print(f'Scheduling for {entry_time}.')
|
||||||
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade, schedule_time)
|
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade, schedule_time)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
|
||||||
print('Trade filters prevent trading today.')
|
|
Loading…
Reference in New Issue
Block a user