This project automates the process of fetching daily stock data using the Alpha Vantage API and appending it to a Google Sheet. It includes smart validation, retry logic, and runs automatically every day at 9 AM EST via GitHub Actions.
- Fetches stock data for 10 major companies
- Appends daily data to Google Sheets
- Automatically adds headers (if missing)
- Skips duplicate entries
- Includes retry logic for API errors
- Creates a local CSV backup (
stock-backup.csv) - Validates latest row using a test script
- Fully automated using GitHub Actions
- Credentials handled securely via GitHub Secrets
- Node.js
- Alpha Vantage API
- Google Sheets API
- GitHub Actions
- AAPL
- MSFT
- GOOGL
- AMZN
- META
- TSLA
- NVDA
- NFLX
- INTC
- IBM
git clone https://github.com/yourusername/stock-automation.git
cd stock-automationnpm installSHEET_ID=your_google_sheet_id_here
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key_here- Go to Google Cloud Console
- Create a project and enable Google Sheets API
- Create a Service Account and download
credentials.json - Share your Google Sheet with the service account’s email as Editor
node index.js # Fetches and writes stock data
node test.js # Verifies latest row matches Alpha Vantage APIThis project runs daily at 9 AM EST via GitHub Actions.
SHEET_IDALPHA_VANTAGE_API_KEYGOOGLE_CREDENTIALS_BASE64→ base64-encodedcredentials.json
The workflow:
- Generates
.envon the fly - Reconstructs
credentials.jsonsecurely - Runs
index.js - Runs
test.jsto validate the update
Sheet:
Date | Symbol | Open | Close | High | Low | Volume
-----------|--------|--------|--------|--------|--------|--------
2025-04-10 | AAPL | 172.56 | 175.20 | 176.10 | 171.90 | 43000000
CSV backup:
stock-backup.csv (auto-generated after each run)
test.js fetches current stock data from Alpha Vantage
and compares it with the latest row in your sheet.
.
├── index.js ← main automation script
├── test.js ← data validation script
├── .env ← your API keys (excluded from GitHub)
├── credentials.json ← Google API credentials (not committed)
├── stock-backup.csv ← auto-generated backup
├── .github/workflows/ ← GitHub Actions automation
├── README.md
.envandcredentials.jsonare excluded from GitHub- GitHub Secrets are used for secure deployment