Filter trading days according to the current volatility regime

This commit is contained in:
moshferatu 2024-02-13 14:30:22 -08:00
parent 9b6405dc30
commit 786364a8af

View File

@ -1,6 +1,7 @@
import schedule
import time
from backtesting.filter import VolatilityRegimeFilter
from datetime import datetime
from dotenv import load_dotenv
from ibkr import Client
@ -13,6 +14,8 @@ load_dotenv()
eastern_timezone = 'America/New_York'
trade_filters = [VolatilityRegimeFilter()]
def enter_trade():
job_process = Process(target = enter_iron_condor)
job_process.start()
@ -27,11 +30,14 @@ def connection_successful():
return False
if __name__ == '__main__':
now = datetime.now(timezone(eastern_timezone))
if all(filter.trade_allowed(now) for filter in trade_filters):
print('Trade filters allow for trading today.')
if connection_successful():
print('Connected to IBKR.')
now = datetime.now(timezone(eastern_timezone))
entry_times = getenv('ENTRY_TIMES').split(',')
for entry_time in entry_times:
schedule_time = datetime.strptime(entry_time, '%H:%M:%S').replace(
@ -51,3 +57,5 @@ if __name__ == '__main__':
time.sleep(1)
else:
print('ERROR: Cannot connect to IBKR. Ensure that TWS / Gateway is running.')
else:
print('Trade filters prevent trading today.')