|
| 1 | +# Stock Price Tracker 📈 |
| 2 | + |
| 3 | +A comprehensive Python application that tracks stock prices using Yahoo Finance API, visualizes daily/weekly trends with interactive charts, and sends automated Telegram notifications for price movements and alerts. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## ✨ Features |
| 10 | + |
| 11 | +- 📊 **Real-time Stock Data**: Fetch live stock prices and historical data using Yahoo Finance API |
| 12 | +- 📈 **Daily & Weekly Trends**: Visualize price movements over different timeframes |
| 13 | +- 🎨 **Multiple Chart Types**: Line charts, candlestick charts, volume analysis, and summary reports |
| 14 | +- 📱 **Telegram Alerts**: Receive instant notifications for price changes and threshold alerts |
| 15 | +- 🎯 **Price Thresholds**: Set custom price alerts and get notified when triggered |
| 16 | +- 📉 **Technical Analysis**: Moving averages, daily returns, and price distribution analysis |
| 17 | +- 💾 **Export Functionality**: Save charts as PNG/HTML files for reporting |
| 18 | +- 🖥️ **Command-line Interface**: Easy-to-use CLI with multiple options |
| 19 | + |
| 20 | +## 📋 Requirements |
| 21 | + |
| 22 | +- Python 3.8 or higher |
| 23 | +- Internet connection (for fetching stock data) |
| 24 | +- Telegram Bot (optional, for alerts) |
| 25 | + |
| 26 | +## 🚀 Installation |
| 27 | + |
| 28 | +1. **Clone or download this project** |
| 29 | + ```bash |
| 30 | + cd Stock-Price-Tracker |
| 31 | + ``` |
| 32 | + |
| 33 | +2. **Install required dependencies** |
| 34 | + ```bash |
| 35 | + pip install -r requirements.txt |
| 36 | + ``` |
| 37 | + |
| 38 | +3. **Set up Telegram Bot (Optional but recommended)** |
| 39 | + |
| 40 | + To receive price alerts via Telegram: |
| 41 | + |
| 42 | + - **Create a Telegram Bot:** |
| 43 | + 1. Open Telegram and search for `@BotFather` |
| 44 | + 2. Send `/newbot` command |
| 45 | + 3. Follow instructions to create your bot |
| 46 | + 4. Copy the **Bot Token** provided |
| 47 | + |
| 48 | + - **Get your Chat ID:** |
| 49 | + 1. Start a chat with your new bot |
| 50 | + 2. Search for `@userinfobot` on Telegram |
| 51 | + 3. Start a chat and it will show your **Chat ID** |
| 52 | + |
| 53 | + - **Configure environment variables:** |
| 54 | + ```bash |
| 55 | + # Copy the example file |
| 56 | + cp config/.env.example config/.env |
| 57 | + |
| 58 | + # Edit config/.env and add your credentials |
| 59 | + TELEGRAM_BOT_TOKEN=your_bot_token_here |
| 60 | + TELEGRAM_CHAT_ID=your_chat_id_here |
| 61 | + ``` |
| 62 | + |
| 63 | +## 📖 Usage |
| 64 | + |
| 65 | +### Basic Commands |
| 66 | + |
| 67 | +**Track daily prices:** |
| 68 | +```bash |
| 69 | +python stock_tracker.py AAPL --daily |
| 70 | +``` |
| 71 | + |
| 72 | +**Track weekly prices:** |
| 73 | +```bash |
| 74 | +python stock_tracker.py GOOGL --weekly |
| 75 | +``` |
| 76 | + |
| 77 | +**Get stock information:** |
| 78 | +```bash |
| 79 | +python stock_tracker.py TSLA --info |
| 80 | +``` |
| 81 | + |
| 82 | +### Advanced Usage |
| 83 | + |
| 84 | +**Track with custom timeframe:** |
| 85 | +```bash |
| 86 | +# 60 days of daily data |
| 87 | +python stock_tracker.py MSFT --daily --days 60 |
| 88 | +
|
| 89 | +# 24 weeks of weekly data |
| 90 | +python stock_tracker.py AMZN --weekly --weeks 24 |
| 91 | +``` |
| 92 | + |
| 93 | +**Save charts without displaying:** |
| 94 | +```bash |
| 95 | +python stock_tracker.py AAPL --daily --save-plots --no-plot |
| 96 | +``` |
| 97 | + |
| 98 | +**Enable Telegram alerts:** |
| 99 | +```bash |
| 100 | +# Track with alert notification |
| 101 | +python stock_tracker.py TSLA --daily --telegram --alert |
| 102 | +
|
| 103 | +# Check price threshold and alert |
| 104 | +python stock_tracker.py AAPL --threshold 150 --threshold-type above --telegram |
| 105 | +``` |
| 106 | + |
| 107 | +**Price threshold monitoring:** |
| 108 | +```bash |
| 109 | +# Alert when price goes above $200 |
| 110 | +python stock_tracker.py GOOGL --threshold 200 --threshold-type above --telegram |
| 111 | +
|
| 112 | +# Alert when price goes below $100 |
| 113 | +python stock_tracker.py MSFT --threshold 100 --threshold-type below --telegram |
| 114 | +``` |
| 115 | + |
| 116 | +### Command-line Arguments |
| 117 | + |
| 118 | +| Argument | Description | Default | |
| 119 | +|----------|-------------|---------| |
| 120 | +| `ticker` | Stock ticker symbol (required) | - | |
| 121 | +| `--daily` | Track daily prices | False | |
| 122 | +| `--weekly` | Track weekly prices | False | |
| 123 | +| `--days` | Number of days to track | 30 | |
| 124 | +| `--weeks` | Number of weeks to track | 12 | |
| 125 | +| `--plot` | Display plots | True | |
| 126 | +| `--no-plot` | Don't display plots | False | |
| 127 | +| `--save-plots` | Save plots to files | False | |
| 128 | +| `--telegram` | Enable Telegram alerts | False | |
| 129 | +| `--alert` | Send Telegram alert | False | |
| 130 | +| `--threshold` | Price threshold for alerts | None | |
| 131 | +| `--threshold-type` | Threshold type (above/below) | above | |
| 132 | +| `--info` | Display stock info only | False | |
| 133 | +
|
| 134 | +## 📊 Example Output |
| 135 | +
|
| 136 | +### Console Output |
| 137 | +``` |
| 138 | +============================================================ |
| 139 | +📈 STOCK PRICE TRACKER |
| 140 | +============================================================ |
| 141 | +🔍 Validating ticker symbol: AAPL |
| 142 | +✅ Ticker AAPL is valid |
| 143 | +
|
| 144 | +============================================================ |
| 145 | +📊 STOCK INFORMATION: AAPL |
| 146 | +============================================================ |
| 147 | +Company: Apple Inc. |
| 148 | +Sector: Technology |
| 149 | +Industry: Consumer Electronics |
| 150 | +Current Price: $178.45 |
| 151 | +Previous Close: $175.20 |
| 152 | +52W High: $198.23 |
| 153 | +52W Low: $124.17 |
| 154 | +Market Cap: $2850.00B |
| 155 | +============================================================ |
| 156 | +
|
| 157 | +📈 Fetching 30 days of data for AAPL... |
| 158 | +✅ Retrieved 30 days of data |
| 159 | +
|
| 160 | +──────────────────────────────────────────────────────────── |
| 161 | +📊 DAILY STATISTICS |
| 162 | +──────────────────────────────────────────────────────────── |
| 163 | +Start Price: $165.30 |
| 164 | +End Price: $178.45 |
| 165 | +Change: $13.15 (7.95%) |
| 166 | +Highest: $180.50 |
| 167 | +Lowest: $164.90 |
| 168 | +──────────────────────────────────────────────────────────── |
| 169 | +``` |
| 170 | +
|
| 171 | +### Telegram Alert Examples |
| 172 | +
|
| 173 | +**Daily Summary Alert:** |
| 174 | +``` |
| 175 | +📊 DAILY SUMMARY: AAPL |
| 176 | +
|
| 177 | +📈 Overall: UP 7.95% |
| 178 | +
|
| 179 | +💰 Opening: $165.30 |
| 180 | +💵 Closing: $178.45 |
| 181 | +🔼 High: $180.50 |
| 182 | +🔽 Low: $164.90 |
| 183 | +📊 Change: $13.15 (+7.95%) |
| 184 | +
|
| 185 | +📅 Date: 2025-12-08 10:30:45 |
| 186 | +``` |
| 187 | +
|
| 188 | +**Threshold Alert:** |
| 189 | +``` |
| 190 | +🔔 THRESHOLD ALERT: AAPL |
| 191 | +
|
| 192 | +↗️ Price is now above $175.00! |
| 193 | +
|
| 194 | +💰 Current Price: $178.45 |
| 195 | +🎯 Threshold: $175.00 |
| 196 | +
|
| 197 | +📅 Time: 2025-12-08 10:30:45 |
| 198 | +``` |
| 199 | +
|
| 200 | +## 📁 Project Structure |
| 201 | +
|
| 202 | +``` |
| 203 | +Stock-Price-Tracker/ |
| 204 | +├── stock_tracker.py # Main application |
| 205 | +├── utils/ |
| 206 | +│ ├── __init__.py |
| 207 | +│ ├── yahoo_finance.py # Yahoo Finance API integration |
| 208 | +│ ├── plotter.py # Chart generation & visualization |
| 209 | +│ └── telegram_alert.py # Telegram bot integration |
| 210 | +├── config/ |
| 211 | +│ └── .env.example # Environment variables template |
| 212 | +├── assets/ |
| 213 | +│ └── img/ # Generated charts and screenshots |
| 214 | +├── requirements.txt # Python dependencies |
| 215 | +└── README.md # Documentation |
| 216 | +``` |
| 217 | +
|
| 218 | +## 🛠️ Tech Stack |
| 219 | +
|
| 220 | +| Technology | Purpose | |
| 221 | +|------------|---------| |
| 222 | +| **yfinance** | Yahoo Finance API for stock data | |
| 223 | +| **pandas** | Data manipulation and analysis | |
| 224 | +| **matplotlib** | Static chart generation | |
| 225 | +| **plotly** | Interactive candlestick charts | |
| 226 | +| **python-telegram-bot** | Telegram bot integration | |
| 227 | +| **python-dotenv** | Environment variable management | |
| 228 | +
|
| 229 | +## 📈 Visualization Features |
| 230 | +
|
| 231 | +1. **Price Trend Chart** |
| 232 | + - Line chart with closing prices |
| 233 | + - 7-day and 30-day moving averages |
| 234 | + - Clean, professional styling |
| 235 | +
|
| 236 | +2. **Candlestick Chart** |
| 237 | + - Interactive OHLC (Open, High, Low, Close) visualization |
| 238 | + - Volume bar chart |
| 239 | + - Zoom and pan capabilities |
| 240 | +
|
| 241 | +3. **Volume Analysis** |
| 242 | + - Price vs. volume correlation |
| 243 | + - Average volume indicators |
| 244 | + - Color-coded volume bars |
| 245 | +
|
| 246 | +4. **Summary Report** |
| 247 | + - Comprehensive multi-panel view |
| 248 | + - Price statistics summary |
| 249 | + - Daily range visualization |
| 250 | +
|
| 251 | +## 🔔 Telegram Alerts |
| 252 | +
|
| 253 | +The app sends various types of alerts: |
| 254 | +
|
| 255 | +- **📊 Price Updates**: Regular stock price summaries |
| 256 | +- **🚨 Threshold Alerts**: Notifications when price crosses set levels |
| 257 | +- **📈 Daily Summaries**: End-of-day price reports with statistics |
| 258 | +- **❌ Error Alerts**: Notifications for any issues or errors |
| 259 | +
|
| 260 | +## 🎯 Use Cases |
| 261 | +
|
| 262 | +- **Day Traders**: Monitor intraday price movements with alerts |
| 263 | +- **Long-term Investors**: Track weekly trends and major price changes |
| 264 | +- **Portfolio Monitoring**: Set threshold alerts for multiple stocks |
| 265 | +- **Market Research**: Analyze historical trends and patterns |
| 266 | +- **Automated Reporting**: Generate and save charts for presentations |
| 267 | +
|
| 268 | +## 🔍 Supported Stock Symbols |
| 269 | +
|
| 270 | +Any valid ticker symbol from Yahoo Finance, including: |
| 271 | +- **US Stocks**: AAPL, GOOGL, MSFT, TSLA, AMZN, etc. |
| 272 | +- **International**: Use country suffix (e.g., RELIANCE.NS for India) |
| 273 | +- **ETFs**: SPY, QQQ, VTI, etc. |
| 274 | +- **Cryptocurrencies**: BTC-USD, ETH-USD, etc. |
| 275 | +
|
| 276 | +## 🤝 Contributing |
| 277 | +
|
| 278 | +Contributions are welcome! Feel free to: |
| 279 | +- Report bugs or issues |
| 280 | +- Suggest new features |
| 281 | +- Improve documentation |
| 282 | +- Submit pull requests |
| 283 | +
|
| 284 | +## 📝 License |
| 285 | +
|
| 286 | +This project is open source and available for educational purposes. |
| 287 | +
|
| 288 | +## ⚠️ Disclaimer |
| 289 | +
|
| 290 | +This tool is for informational and educational purposes only. It should not be considered as financial advice. Always do your own research before making investment decisions. |
| 291 | +
|
| 292 | +## 👨💻 Author |
| 293 | +
|
| 294 | +Created as part of the [Python-Projects](https://github.com/Grow-with-Open-Source/Python-Projects) repository. |
| 295 | +
|
| 296 | +--- |
| 297 | +
|
| 298 | +**Happy Trading! 📈💰** |
0 commit comments