Prevent scheduling trades for entry time that have already elapsed
This commit is contained in:
parent
5766a49164
commit
cd473ded8a
@ -8,10 +8,12 @@ from ibkr import Client
|
|||||||
from iron_condor import enter_iron_condor
|
from iron_condor import enter_iron_condor
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from os import getenv
|
from os import getenv
|
||||||
|
from pytz import timezone
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
entry_time_format = '%H:%M:%S'
|
entry_time_format = '%H:%M:%S'
|
||||||
|
eastern_timezone = 'America/New_York'
|
||||||
|
|
||||||
def available_entry_times():
|
def available_entry_times():
|
||||||
start = datetime.strptime('09:35:00', entry_time_format)
|
start = datetime.strptime('09:35:00', entry_time_format)
|
||||||
@ -57,11 +59,22 @@ if __name__ == '__main__':
|
|||||||
if connection_successful():
|
if connection_successful():
|
||||||
print('Connected to IBKR.')
|
print('Connected to IBKR.')
|
||||||
|
|
||||||
|
now = datetime.now(timezone(eastern_timezone))
|
||||||
|
|
||||||
entry_times = best_entry_times()
|
entry_times = best_entry_times()
|
||||||
print(entry_times)
|
print(entry_times)
|
||||||
for entry_time in entry_times:
|
for entry_time in entry_times:
|
||||||
print(f'Scheduling for {entry_time}.')
|
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
|
||||||
schedule.every().day.at(entry_time, 'America/New_York').do(enter_trade)
|
year = now.year,
|
||||||
|
month = now.month,
|
||||||
|
day = now.day,
|
||||||
|
tzinfo = now.tzinfo
|
||||||
|
)
|
||||||
|
|
||||||
|
# Prevent scheduling for times that have already elapsed.
|
||||||
|
if schedule_time > now:
|
||||||
|
print(f'Scheduling for {entry_time}.')
|
||||||
|
schedule.every().day.at(entry_time, eastern_timezone).do(enter_trade)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
schedule.run_pending()
|
schedule.run_pending()
|
||||||
|
Loading…
Reference in New Issue
Block a user