Skip to content

A Bitcoin price tracker CLI application written in Go that provides real-time price updates, alerts, and historical logging capabilities.

Notifications You must be signed in to change notification settings

helioLJ/bitcoin_tracker_in_go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitcoin Price Tracker

A command-line application that tracks Bitcoin prices in real-time, provides price alerts, and logs historical data.

Bitcoin Price Tracker

Features

  • 🪙 Real-time Bitcoin price tracking
  • 🌍 Multiple currency support
  • 🚨 Configurable price alerts
  • 📊 Historical price logging
  • ⚡ Non-blocking updates using goroutines
  • 🎨 Clean terminal UI

Setup

  1. Clone the repository
git clone https://github.com/helioLJ/bitcoin-tracker.git
cd bitcoin-tracker
  1. Install dependencies
go mod download
  1. 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 1m
  • CURRENCY: Default currency (e.g., usd, eur, gbp)
  • ALERT_THRESHOLD: Price threshold for alerts

Usage

  1. Run the application
go run .
  1. Enter your preferred currency when prompted, or press Enter to use the default from .env

  2. Monitor prices - The UI will show:

    • Current Bitcoin price
    • Session price change percentage
    • Last update time
    • Price alerts when thresholds are crossed
  3. View price history in price_history.csv

  4. Exit with Ctrl+C

Go Concepts Used

1. Packages and Project Structure

├── 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

2. Concurrency

  • Goroutines: Used for background price fetching
  • Channels: Communication between components
    • priceChan: Price updates
    • errorChan: Error handling
    • alertChan: Price alerts
    • stopChan: Graceful shutdown

3. Types and Interfaces

type Tracker struct {
    config    utils.Config
    alerts    []Alert
    priceChan chan PriceData
    // ...
}

type PriceData struct {
    Price     float64
    Currency  string
    Timestamp time.Time
}

4. Error Handling

  • Custom error types with context
  • Graceful error display in UI
  • Error propagation through channels

5. File I/O

  • Configuration loading from .env
  • CSV logging of price history

Dependencies

  • github.com/joho/godotenv: Environment variable management
  • Standard library packages:
    • net/http: API requests
    • encoding/json: JSON parsing
    • time: Time operations
    • os: File operations

Contributing

Feel free to submit issues and pull requests.

About

A Bitcoin price tracker CLI application written in Go that provides real-time price updates, alerts, and historical logging capabilities.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages