backtest-automation/backtest_scheduler.py

30 lines
786 B
Python
Raw Normal View History

import schedule
import time
import traceback
from datetime import datetime, timedelta
from discord_messaging import send_message
from dotenv import load_dotenv
from os import getenv
from download_spx_quotes import download_quotes
from run_backtest import run_backtests
load_dotenv()
def backtest_automation():
try:
download_quotes()
end_date = datetime.now()
start_date = end_date - timedelta(days = 1)
run_backtests(start_date, end_date)
except:
2024-01-19 15:40:37 +00:00
send_message('Backtest automation failed!', to_user_id = getenv('USER_ID'))
traceback.print_exc()
if __name__ == '__main__':
schedule.every().day.at('03:00', 'America/Los_Angeles').do(backtest_automation)
while True:
schedule.run_pending()
time.sleep(1)