Skip to content

A simple, beginner-friendly command-line cryptocurrency portfolio tracker written in Rust.

License

Notifications You must be signed in to change notification settings

paaggeli/rusty_coinwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rusty Coinwatch

A simple, beginner-friendly command-line cryptocurrency portfolio tracker written in Rust. Perfect for learning Rust concepts.

Track your crypto positions manually with buy and sell commands, fetch live prices from CoinGecko, and view your portfolio value and unrealized P/L in a clean table format.

Features

  • πŸ’° Track cryptocurrency positions manually
  • πŸ“ˆ Fetch live prices from CoinGecko API
  • πŸ“Š Display portfolio in a formatted table
  • πŸ’΅ Calculate unrealized profit/loss (P/L)
  • πŸ“‰ Show P/L percentage for each position
  • πŸ’Ύ Persistent storage (saves to JSON file)
  • 🚫 No wallets, no private keys, no transaction history

Prerequisites

Before you begin, make sure you have Rust installed on your system.

Installing Rust

Linux/macOS:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Windows: Download and run the installer from rustup.rs

Verify installation:

rustc --version
cargo --version

Installation

Clone

# Clone the repository (if you have it on GitHub)
git clone https://github.com/yourusername/rusty_coinwatch.git

# Navigate to the project directory
cd rusty_coinwatch

Option 1: Build the project

# Build the project
cargo build --release

# The executable will be in target/release/

Option 2: Install directly with Cargo

cargo install --path .

Usage

Basic Commands

Buy cryptocurrency (add to position):

coinwatch buy bitcoin 0.5 50000
coinwatch buy ethereum 2.0 3000

# If you are running the app during development
cargo run -- buy bitcoin 0.5 50000
cargo run -- buy ethereum 2.0 3000

Parameters:

  • bitcoin - CoinGecko coin ID (e.g., bitcoin, ethereum, solana, cardano)
  • 0.5 - Amount/quantity you're buying
  • 50000 - Price per coin in USD

View your portfolio:

coinwatch portfolio

# If you are running the app during development
cargo run -- portfolio

Output example:

πŸ“Š Your Portfolio:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Coin     β”‚ Amount    β”‚ Avg Buy Price β”‚ Current Price  β”‚ Current Value  β”‚ P/L     β”‚ P/L %   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ bitcoin  β”‚ 0.50000000β”‚ $50000.00     β”‚ $52000.00      β”‚ $26000.00      β”‚ +1000.00β”‚ +4.00%  β”‚
β”‚ ethereum β”‚ 2.00000000β”‚ $3000.00      β”‚ $3200.00       β”‚ $6400.00       β”‚ +400.00 β”‚ +6.67%  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ TOTAL    β”‚           β”‚               β”‚                β”‚ $32400.00      β”‚ +1400.00β”‚ +4.51%  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Sell cryptocurrency (reduce position):

coinwatch sell bitcoin 0.2

# If you are running the app during development
cargo run -- sell bitcoin 0.2

Output:

βœ“ Sold 0.2 bitcoin

Check current price of a coin:

coinwatch price solana

# If you are running the app during development
cargo run -- price solana

Output:

πŸ’° solana current price: $145.32

Delete a coin from portfolio:

coinwatch delete ethereum

# If you are running the app during development
cargo run -- delete ethereum

Output:

βœ“ Removed ethereum from your portfolio

Get help:

coinwatch --help

# If you are running the app during development
cargo run -- --help

Supported Coins

The app supports all the CoinGecko coin IDs.

You can find the coin ID on CoinGecko.

How It Works

Portfolio Storage

The application stores your portfolio in a portfolio.json file in the same directory where you run the program. Each position has:

  • coin_id: The CoinGecko coin identifier
  • amount: How much of the coin you own
  • avg_buy_price: Your average purchase price (calculated automatically)

Example portfolio.json:

{
  "coins": [
    {
      "coin_id": "bitcoin",
      "amount": 0.5,
      "avg_buy_price": 50000.0
    },
    {
      "coin_id": "ethereum",
      "amount": 2.0,
      "avg_buy_price": 3000.0
    }
  ]
}

Average Buy Price Calculation

When you buy more of a coin you already own, the app calculates a weighted average:

New Avg Price = (Old Amount Γ— Old Price + New Amount Γ— New Price) / Total Amount

Example:

  • You buy 0.5 BTC at $50,000
  • Later you buy 0.3 BTC at $48,000
  • Your new average: (0.5 Γ— 50000 + 0.3 Γ— 48000) / 0.8 = $49,250

Live Price Fetching

The app uses the free CoinGecko API to fetch current cryptocurrency prices. No API key required for basic usage.

API Rate Limits

The CoinGecko free API has rate limits:

  • ~10-50 calls/minute (varies)
  • If you have many coins, the portfolio command may hit rate limits

Project Structure

rusty_coinwatch/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs         # Entry point, CLI parsing, command routing
β”‚   β”œβ”€β”€ models.rs       # Data structures (Coin, Portfolio)
β”‚   β”œβ”€β”€ storage.rs      # File I/O (load/save portfolio to JSON)
β”‚   └── api.rs          # CoinGecko API integration
β”œβ”€β”€ Cargo.toml          # Project dependencies
β”œβ”€β”€ portfolio.json      # Portfolio storage (created automatically)
β”œβ”€β”€ README.md            # This file
β”œβ”€β”€ LICENSE              # License information
└── CONTRIBUTING.md      # Contribution guidelines

Dependencies

This project uses the following crates:

  • clap - Command-line argument parsing with derive macros
  • serde & serde_json - JSON serialization/deserialization
  • reqwest - HTTP client for API requests
  • tokio - Async runtime
  • prettytable-rs - Terminal table formatting

πŸ“– Detailed Tutorial: For a comprehensive, step-by-step guide to building this project from scratch, check out my blog:

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

Ways to Contribute

Contributions are welcome! Feel free to:

  • πŸ› Report bugs
  • πŸ’‘ Suggest new features
  • πŸ“ Improve documentation
  • 🎨 Enhance the UI/UX

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author


Happy tracking! πŸ¦€πŸ“ˆ

About

A simple, beginner-friendly command-line cryptocurrency portfolio tracker written in Rust.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages