A command-line application that tracks Bitcoin prices in real-time, provides price alerts, and logs historical data.
- 🪙 Real-time Bitcoin price tracking
- 🌍 Multiple currency support
- 🚨 Configurable price alerts
- 📊 Historical price logging
- ⚡ Non-blocking updates using goroutines
- 🎨 Clean terminal UI
- Clone the repository
git clone https://github.com/helioLJ/bitcoin-tracker.git
cd bitcoin-tracker
- Install dependencies
go mod download
- Configure the application
Create a .env
file in the root directory:
UPDATE_INTERVAL=5s
CURRENCY=usd
ALERT_THRESHOLD=100000
UPDATE_INTERVAL
: How often to fetch new prices (e.g., 5s, 1m) // To prevent rate limiting, set to 1mCURRENCY
: Default currency (e.g., usd, eur, gbp)ALERT_THRESHOLD
: Price threshold for alerts
- Run the application
go run .
-
Enter your preferred currency when prompted, or press Enter to use the default from
.env
-
Monitor prices - The UI will show:
- Current Bitcoin price
- Session price change percentage
- Last update time
- Price alerts when thresholds are crossed
-
View price history in
price_history.csv
-
Exit with Ctrl+C
├── main.go # Application entry point
├── tracker/ # Core tracking functionality
│ ├── api.go # API interaction
│ ├── models.go # Data structures
│ └── tracker.go # Price tracking logic
└── utils/ # Utility functions
├── config.go # Configuration management
├── error.go # Error handling
└── file.go # File operations
- Goroutines: Used for background price fetching
- Channels: Communication between components
priceChan
: Price updateserrorChan
: Error handlingalertChan
: Price alertsstopChan
: Graceful shutdown
type Tracker struct {
config utils.Config
alerts []Alert
priceChan chan PriceData
// ...
}
type PriceData struct {
Price float64
Currency string
Timestamp time.Time
}
- Custom error types with context
- Graceful error display in UI
- Error propagation through channels
- Configuration loading from
.env
- CSV logging of price history
github.com/joho/godotenv
: Environment variable management- Standard library packages:
net/http
: API requestsencoding/json
: JSON parsingtime
: Time operationsos
: File operations
Feel free to submit issues and pull requests.