A production-ready, real-time stock tracking web application built with Go backend and vanilla JavaScript frontend. Track stock prices with live WebSocket updates, beautiful responsive UI, and easy cloud deployment.
- β Real-Time Updates - WebSocket-powered live stock price updates without page refresh
- β Beautiful UI - Responsive, mobile-first design with dark mode
- β Stock Watchlist - Add/remove stocks and track them easily
- β Interactive Charts - View price history across 5 time periods (1D, 1W, 1M, 3M, 1Y)
- β Market Summary - Quick overview of gains/losses
- β Search Function - Find stocks quickly
- β Local Persistence - Watchlist saved in browser
- β Auto Reconnection - WebSocket with exponential backoff
- β Multi-Provider API - Finnhub, Alpha Vantage, or Mock data
- β Goroutine-Based Concurrency - Efficient background price updates
- β In-Memory Caching - 30-second TTL for optimal performance
- β Docker Ready - Multi-stage build, minimal image size
- β Graceful Shutdown - Proper signal handling
- β CORS Configured - Ready for cross-origin requests
- β Health Checks - Built-in monitoring endpoint
- Desktop - Full-featured layout (1400px+)
- Tablet - Optimized layout (768px - 1399px)
- Mobile - Touch-friendly design (480px - 767px)
docker-compose up
# Open http://localhost:8080cd backend
go run main.go
# Open http://localhost:8080cd backend
go build -o stock-tracker
./stock-tracker- Go: 1.21 or higher
- Docker: (optional, for containerization)
- API Key: (optional, for real stock data)
backend/
βββ main.go # Server entry point
βββ config/ # Configuration management
βββ models/ # Data structures
βββ utils/ # API client & helpers
βββ services/ # Business logic
βββ controllers/ # HTTP handlers
βββ routes/ # Route definitions
βββ middleware/ # CORS & error handling
βββ websocket/ # WebSocket hub
Key Technologies:
- Gin - HTTP framework
- Gorilla WebSocket - Real-time communication
- godotenv - Environment configuration
frontend/
βββ index.html # HTML structure
βββ css/
β βββ styles.css # Responsive styling (1100+ lines)
βββ js/
βββ websocket.js # WebSocket client
βββ app.js # Application logic (780 lines)
Key Technologies:
- Chart.js - Price visualization
- Vanilla JS - No frameworks, lightweight
- CSS3 - Modern responsive design
- LocalStorage - Data persistence
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/stocks/:symbol |
Get stock data |
| GET | /api/stocks?symbols=AAPL,GOOGL |
Get multiple stocks |
| GET | /api/stocks/search?q=AAPL |
Search stocks |
| GET | /api/stocks/defaults |
Get default stocks |
| GET | /api/health |
Health check |
| POST | /api/cache/invalidate |
Clear cache |
Connect to: ws://localhost:8080/ws
Messages:
{"type": "subscribe", "symbol": "AAPL"}- Subscribe to updates{"type": "unsubscribe", "symbol": "AAPL"}- Unsubscribe{"type": "list"}- Get tracked stocks{"type": "update", "data": {...}}- Price update (received)
Create a .env file in the root directory:
PORT=8080
ENV=development
API_PROVIDER=mock # Options: mock, finnhub, alpha_vantage
API_KEY=your_api_key # For real data providers
UPDATE_INTERVAL=5000 # milliseconds
MAX_CONNECTIONS=1000-
Mock (Default)
- No API key needed
- Realistic simulated data
- Perfect for testing
-
Finnhub (Recommended)
- Free tier: 60 requests/minute
- Sign up: https://finnhub.io
-
Alpha Vantage
- Free tier: 5 requests/minute
- Sign up: https://www.alphavantage.co
docker build -t stock-tracker .docker run -p 8080:8080 -e API_PROVIDER=mock stock-trackerdocker-compose up # Development
docker-compose up -d # Background
docker-compose down # Stop| Document | Purpose | Read Time |
|---|---|---|
| START_HERE.md | Project overview & quick links | 2 min |
| QUICKSTART.md | 5-minute setup guide | 5 min |
| API_REFERENCE.md | Complete API documentation | 15 min |
| deploy.md | Cloud deployment guides (6 platforms) | 30 min |
| BUILD_SUMMARY.md | Project completion verification | 5 min |
| FILE_MANIFEST.md | Complete file listing | 10 min |
| DOCUMENTATION_INDEX.md | Documentation guide | 5 min |
Deploy to multiple cloud platforms in minutes:
- Render - Easiest for beginners
- Railway - GitHub integration
- Fly.io - Global deployment
- AWS - Enterprise-grade
- DigitalOcean - Developer-friendly
- Heroku - Legacy support
See deploy.md for step-by-step guides
- Language: Go 1.21+
- Framework: Gin v1.10.0
- Real-time: Gorilla WebSocket v1.5.1
- Config: godotenv v1.5.1
- HTML5, CSS3, JavaScript (ES6+)
- Charts: Chart.js v3.9.1
- Storage: Browser LocalStorage
- No frameworks - Pure vanilla JS
- Container: Docker (multi-stage build)
- Orchestration: Docker Compose
- OS: Alpine Linux (minimal footprint)
βββ backend/ # Go server code
βββ frontend/ # HTML/CSS/JS UI
βββ Dockerfile # Container config
βββ docker-compose.yml # Local dev setup
βββ .env.example # Configuration template
βββ *.md # Documentation files
cd backend
go build -o stock-trackercd backend
go run main.gogo install github.com/cosmtrek/air@latest
cd backend
air- Run
docker-compose up - Open http://localhost:8080
- Add stocks to watchlist
- Watch real-time updates
- Try different time periods on charts
# Get single stock
curl http://localhost:8080/api/stocks/AAPL
# Get multiple stocks
curl "http://localhost:8080/api/stocks?symbols=AAPL,GOOGL,MSFT"
# Health check
curl http://localhost:8080/api/health- β CORS headers configured
- β Input validation
- β Error handling without sensitive info
- β Environment-based secrets
- β Graceful error recovery
- Use HTTPS (automatic on cloud platforms)
- Set strong API keys
- Enable request logging
- Monitor error rates
- Rate limit if needed
- Initial Load: < 500ms
- WebSocket Latency: < 10ms
- Concurrent Connections: 1000+
- Memory Usage: ~50-100MB
- CPU: Minimal (idle < 5%)
# Clear cache
docker system prune -a
# Rebuild
docker-compose build --no-cache
docker-compose up# Change port in .env or docker-compose.yml
PORT=8081- Check firewall settings
- Ensure URL uses
ws://orwss:// - Try browser console (F12) for errors
See QUICKSTART.md for more solutions
| Category | Lines | Files |
|---|---|---|
| Go Backend | 1,250+ | 11 |
| Frontend (JS/CSS) | 2,300+ | 4 |
| Documentation | 3,000+ | 7 |
| Configuration | 123 | 5 |
| Total | 6,700+ | 27+ |
Contributions are welcome! Here's how:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow Go conventions (gofmt, golint)
- Keep code modular and testable
- Update documentation as needed
- Test on multiple browsers/devices
This project is licensed under the MIT License - see LICENSE file for details.
Ghanshyam Jha
- GitHub: @GhanshyamJha05
- Email: [Your Email Here]
- Gin Web Framework team
- Gorilla WebSocket contributors
- Chart.js creators
- Stock market data providers (Finnhub, Alpha Vantage)
- Documentation: Start with START_HERE.md
- Quick Setup: See QUICKSTART.md
- Deployment: Check deploy.md
- API Details: Read API_REFERENCE.md
- Issues: Open an GitHub issue with detailed description
- User authentication & accounts
- Database persistence (PostgreSQL/MongoDB)
- Advanced charting with indicators
- Portfolio management
- Mobile app (React Native)
- Social features (sharing, comments)
- Alerts & notifications
- Historical data export
- Sub-100ms page load
- 5000+ concurrent users
- 99.9% uptime
- CDN integration
If you found this project helpful, please give it a star! β
Built with β€οΈ by Ghanshyam Jha
Last Updated: January 2026