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.
- π° 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
Before you begin, make sure you have Rust installed on your system.
Linux/macOS:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shWindows: Download and run the installer from rustup.rs
Verify installation:
rustc --version
cargo --version# 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# Build the project
cargo build --release
# The executable will be in target/release/cargo install --path .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 3000Parameters:
bitcoin- CoinGecko coin ID (e.g., bitcoin, ethereum, solana, cardano)0.5- Amount/quantity you're buying50000- Price per coin in USD
View your portfolio:
coinwatch portfolio
# If you are running the app during development
cargo run -- portfolioOutput 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.2Output:
β Sold 0.2 bitcoin
Check current price of a coin:
coinwatch price solana
# If you are running the app during development
cargo run -- price solanaOutput:
π° solana current price: $145.32
Delete a coin from portfolio:
coinwatch delete ethereum
# If you are running the app during development
cargo run -- delete ethereumOutput:
β Removed ethereum from your portfolio
Get help:
coinwatch --help
# If you are running the app during development
cargo run -- --helpThe app supports all the CoinGecko coin IDs.
You can find the coin ID on CoinGecko.
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
}
]
}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
The app uses the free CoinGecko API to fetch current cryptocurrency prices. No API key required for basic usage.
The CoinGecko free API has rate limits:
- ~10-50 calls/minute (varies)
- If you have many coins, the portfolio command may hit rate limits
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
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:
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Contributions are welcome! Feel free to:
- π Report bugs
- π‘ Suggest new features
- π Improve documentation
- π¨ Enhance the UI/UX
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub: @paaggeli
Happy tracking! π¦π