Skip to content

LamThienLe/etf_watcher

Repository files navigation

ETF Alert System

Automated email alerts for Vietnamese ETF buying opportunities with multi-level signal detection.

Features

  • Monitors 4 ETFs: FUESSV30, E1VFVN30, FUEVFVND, FUESSVFL
  • Multi-level buy signals:
    • 🟡 WEAK - Early warning, monitor closely
    • 🟠 MODERATE - Good buying opportunity
    • 🔴 STRONG - Significant dip, strong buy signal
  • Sends beautiful HTML email alerts with color-coded metrics
  • Fully configurable thresholds via environment variables
  • Runs automatically via GitHub Actions at 4:00 PM ICT (weekdays)

Alert Levels Explained

Signal Strength

The system detects three levels of buy signals based on RSI and Moving Average indicators:

Level RSI Threshold MA Dip Threshold Meaning
🟡 WEAK < 40 3%+ below MA Early opportunity, watch closely
🟠 MODERATE < 35 5%+ below MA Good entry point
🔴 STRONG < 30 7%+ below MA Excellent buying opportunity

Email is sent ONLY when at least one ETF triggers a signal. If all ETFs are above thresholds, no email is sent.

Setup

1. Local Testing

pip install -r requirements.txt

Create a .env file:

cp .env.example .env

Edit .env with your credentials:

SENDER_EMAIL=your-email@gmail.com
SENDER_PASSWORD=your-app-password
RECIPIENT_EMAIL=holla.at.lam@gmail.com
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587

# Configurable thresholds
RSI_WEAK=40
RSI_MODERATE=35
RSI_STRONG=30

MA_DIP_WEAK=3
MA_DIP_MODERATE=5
MA_DIP_STRONG=7

Gmail Setup:

  1. Go to Google Account → Security
  2. Enable 2-Step Verification
  3. Generate App Password: Security → 2-Step Verification → App passwords
  4. Use the 16-character app password (not your regular password)

Test the script:

python etf_alert.py

Debug mode (see all metrics):

python debug_etf.py

2. GitHub Actions Setup

  1. Push this repository to GitHub

  2. Add secrets to your repository:

    • Go to Settings → Secrets and variables → Actions
    • Click "New repository secret" and add each of these:
Secret Name Value Example
SENDER_EMAIL Your Gmail address your-email@gmail.com
SENDER_PASSWORD Gmail app password abcd efgh ijkl mnop
RECIPIENT_EMAIL Email to receive alerts holla.at.lam@gmail.com
SMTP_SERVER SMTP server smtp.gmail.com
SMTP_PORT SMTP port 587
RSI_WEAK Weak RSI threshold 40
RSI_MODERATE Moderate RSI threshold 35
RSI_STRONG Strong RSI threshold 30
MA_DIP_WEAK Weak MA dip % 3
MA_DIP_MODERATE Moderate MA dip % 5
MA_DIP_STRONG Strong MA dip % 7
  1. The workflow will run automatically:
    • Schedule: Monday-Friday at 4:00 PM ICT (9:00 AM UTC)
    • Manual: Go to Actions → ETF Alert System → Run workflow

How It Works

  1. Data Collection: Fetches 50 days of historical data for each ETF
  2. Indicator Calculation:
    • RSI (14-day) - Measures momentum
    • 20-day Moving Average - Identifies trend
  3. Signal Detection: Compares current values against thresholds
  4. Alert Priority: Uses the strongest signal level detected
  5. Email Notification: Sends color-coded HTML email if any signal is detected

Customization

Adjust Alert Sensitivity

Edit your .env file to tune the thresholds:

More aggressive (catch more opportunities):

RSI_WEAK=45
RSI_MODERATE=40
RSI_STRONG=35

MA_DIP_WEAK=2
MA_DIP_MODERATE=4
MA_DIP_STRONG=6

More conservative (fewer but stronger signals):

RSI_WEAK=35
RSI_MODERATE=30
RSI_STRONG=25

MA_DIP_WEAK=5
MA_DIP_MODERATE=7
MA_DIP_STRONG=10

Add/Remove ETFs

Edit etf_alert.py line 264:

etf_symbols = ['fuessv30', 'e1vfvn30', 'fuevfvnd', 'fuessvfl', 'your-new-etf']

File Structure

etf_alert/
├── .github/
│   └── workflows/
│       └── etf_alert.yml    # GitHub Actions workflow
├── etf_alert.py             # Main alert script
├── debug_etf.py             # Debug tool to see all metrics
├── requirements.txt         # Python dependencies
├── .env.example             # Configuration template
├── .gitignore              # Git ignore rules
└── README.md               # This file

Tools

Main Script

python etf_alert.py
  • Checks all ETFs
  • Sends email if signals detected
  • Use this for production

Debug Script

python debug_etf.py
  • Shows detailed metrics for all ETFs
  • Displays configured thresholds
  • Shows which conditions are met
  • Use this to test thresholds

Troubleshooting

No email received:

  • Check GitHub Actions logs
  • Verify email credentials in Secrets
  • Ensure Gmail app password is correct
  • Check spam folder
  • Run python debug_etf.py to see if signals are triggering

Script fails:

  • Verify vnstock library supports the ETF symbols
  • Check internet connection for API access
  • Review error logs in Actions tab
  • Ensure all environment variables are set

Alerts too frequent/infrequent:

  • Run python debug_etf.py to see current metrics
  • Adjust thresholds in .env file
  • Update GitHub Secrets if running on Actions

Example Email

The alert emails include:

  • Beautiful gradient header
  • Color-coded signal strength badges
  • Current price, 20-day MA, RSI metrics
  • Visual indicators showing which thresholds triggered
  • Legend explaining signal levels
  • All ETFs with signals in one email

Contributing

Feel free to customize this for your needs. Key areas to modify:

  • Thresholds in .env
  • ETF list in etf_alert.py
  • Email styling in format_email_body() function
  • Schedule in .github/workflows/etf_alert.yml

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages