Verify connection to IBKR before scheduling trade entry jobs
This commit is contained in:
parent
0fe6181e7c
commit
1cc0c7867f
@ -1,8 +1,13 @@
|
|||||||
import schedule
|
import schedule
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
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
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# TODO: Look up entry times from database.
|
# TODO: Look up entry times from database.
|
||||||
entry_times = []
|
entry_times = []
|
||||||
@ -11,10 +16,24 @@ def enter_trade():
|
|||||||
job_process = Process(target = enter_iron_condor)
|
job_process = Process(target = enter_iron_condor)
|
||||||
job_process.start()
|
job_process.start()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def connection_successful():
|
||||||
for entry_time in entry_times:
|
try:
|
||||||
schedule.every().day.at(entry_time, 'America/Los_Angeles').do(enter_trade)
|
ibkr_host = getenv('IBKR_HOST')
|
||||||
|
ibkr_port = getenv('IBKR_PORT')
|
||||||
|
Client(host = ibkr_host, port = ibkr_port)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
while True:
|
if __name__ == '__main__':
|
||||||
schedule.run_pending()
|
if connection_successful():
|
||||||
time.sleep(1)
|
print('Connected to IBKR.')
|
||||||
|
|
||||||
|
for entry_time in entry_times:
|
||||||
|
schedule.every().day.at(entry_time, 'America/Los_Angeles').do(enter_trade)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
schedule.run_pending()
|
||||||
|
time.sleep(1)
|
||||||
|
else:
|
||||||
|
print('ERROR: Cannot connect to IBKR. Ensure that TWS / Gateway is running.')
|
Loading…
Reference in New Issue
Block a user