Earnings Trade Automation #545
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Earnings Trade Automation | |
| # This workflow runs on push, pull request, and at key US market times for trade open/close (per trade_key_points.md) | |
| on: | |
| schedule: | |
| # 9:40 AM ET (Eastern Time) | |
| - cron: '40 13 * * 1-5' # 9:40 AM ET during EST (UTC-5) | |
| - cron: '40 14 * * 1-5' # 9:40 AM ET during EDT (UTC-4) | |
| # 3:35 PM ET (Eastern Time) | |
| - cron: '35 19 * * 1-5' # 3:35 PM ET during EST (UTC-5) | |
| - cron: '35 20 * * 1-5' # 3:35 PM ET during EDT (UTC-4) | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| APCA_API_KEY_ID: ${{ secrets.APCA_API_KEY_ID }} | |
| APCA_API_SECRET_KEY: ${{ secrets.APCA_API_SECRET_KEY }} | |
| GOOGLE_SCRIPT_URL: ${{ secrets.GOOGLE_SCRIPT_URL }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: true | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Time pip install | |
| run: | | |
| start=$(date +%s) | |
| pip install -r requirements.txt | |
| end=$(date +%s) | |
| echo "Pip install duration: $((end-start)) seconds" | |
| - name: List installed packages | |
| run: pip list | |
| - name: Check for build files | |
| run: | | |
| find . -type d -name "__pycache__" || echo "No __pycache__ found" | |
| find . -name "*.pyc" || echo "No .pyc files found" | |
| - name: List workspace files | |
| run: ls -alR | |
| - name: Validate scheduled time | |
| run: | | |
| current_time=$(TZ="America/New_York" date +'%H:%M') | |
| echo "Current ET Time: $current_time" | |
| current_minutes=$((10#$(echo "$current_time" | cut -d: -f1)*60 + 10#$(echo "$current_time" | cut -d: -f2))) | |
| if ! (( (current_minutes >= 580 && current_minutes <= 610) || (current_minutes >= 935 && current_minutes <= 965) )); then | |
| echo "Not within valid time window (09:40-10:10 or 15:35-16:05 ET). Exiting." | |
| exit 1 | |
| fi | |
| - name: Run workflow | |
| run: python trade_workflow.py | |
| # The bot logic (timing, sizing, etc.) is defined in trade_key_points.md | |
| - name: Commit updated trades.db | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add trades.db | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore: update trades.db" | |
| git push | |
| fi |