DEV Community

Otto
Otto

Posted on

I Built a DCA Crypto Tracker in Python — 200 Lines, Zero Dependencies

Dollar-Cost Averaging is the most boring, most effective way to build a crypto portfolio.

Buy a fixed amount. Regularly. No matter the price.

The problem? Most DCA tools are either oversimplified apps or expensive platforms that want your bank connection. So I built my own in Python — no external libraries, runs in your terminal, data stays local.

Here is how it works.

What the Tool Does

Four features, all in CLI:

  1. Simulate — Enter your monthly budget, entry price, and current price → get ROI, total coins, projected value
  2. Add purchase — Log each buy (crypto, amount, price, date) → stored locally in JSON
  3. Portfolio summary — See all your positions with average cost basis and P&L
  4. DCA Planner — Set frequency (daily/weekly/monthly) → get your next purchase dates

The Core: DCA Simulator

def simulate_dca(args):
    monthly_amount = float(input("Monthly investment (€): "))
    entry_price = float(input("Average entry price (€): "))
    current_price = float(input("Current price (€): "))
    months = int(input("Months invested: "))

    total_invested = monthly_amount * months
    total_coins = total_invested / entry_price
    current_value = total_coins * current_price
    profit_loss = current_value - total_invested
    roi_pct = ((current_value - total_invested) / total_invested) * 100

    print(f"Total invested : {total_invested:.2f}")
    print(f"Coins acquired : {total_coins:.6f}")
    print(f"Current value  : {current_value:.2f}")
    print(f"P&L            : {profit_loss:+.2f} € ({roi_pct:+.1f}%)")
Enter fullscreen mode Exit fullscreen mode

Clean, readable, no magic.

The Portfolio Tracker

def add_purchase(args):
    data = load_data()

    crypto = input("Crypto (BTC, ETH, SOL...): ").strip().upper()
    amount_eur = float(input("Amount in euros: "))
    price = float(input(f"Price of {crypto}: "))
    date_str = input("Date (YYYY-MM-DD): ").strip() or datetime.now().strftime("%Y-%m-%d")

    purchase = {
        "id": len(data["purchases"]) + 1,
        "crypto": crypto,
        "amount_eur": amount_eur,
        "price_eur": price,
        "coins": amount_eur / price,
        "date": date_str,
    }
    data["purchases"].append(purchase)
    save_data(data)  # saves to ~/.dca_tracker.json
Enter fullscreen mode Exit fullscreen mode

Local JSON storage. No cloud, no account, no tracking.

Example Output — Simulate

📊 DCA SIMULATOR
──────────────────────────────────
Monthly investment: 500€
Entry price (BTC): 30,000€
Current price: 95,000€
Months: 24

══════════════════════════════════
💰 Total invested  :   12,000.00 €
🪙 Coins acquired  :   0.400000 BTC
📈 Current value   :   38,000.00 €
──────────────────────────────────
✅ P&L             : + 26,000.00 €
📊 ROI             : +    216.7 %
══════════════════════════════════

🔮 PROJECTION (12 more months at current price)
  Total invested in 1 year : 18,000.00 €
  Total coins              : 0.463158 BTC
  Value (constant price)   : 44,000.00 €
Enter fullscreen mode Exit fullscreen mode

Why DCA Works

The math is simple: if you buy the same euro amount every month, you automatically buy more coins when prices are low and fewer when prices are high.

Over 24 months of BTC DCA (Jan 2022 — Dec 2023, one of the worst bear markets):

  • €500/month = €12,000 invested
  • Average cost basis: ~€24,500/BTC
  • At €95,000 current price: +287% ROI

Vs. lump sum investing in January 2022 at ~€37,000:

  • Same €12,000 invested → current value: ~€30,800 (+157% ROI)

DCA beat lump-sum by 130 percentage points on one of the worst entry years possible.

The DCA Planner

def dca_planner(args):
    crypto = input("Target crypto: ").upper()
    monthly_budget = float(input("Monthly budget (€): "))
    frequency = input("Frequency (daily/weekly/monthly): ") or "monthly"
    months_ahead = int(input("Plan for how many months? ") or "12")

    freq_map = {"daily": 30, "weekly": 4, "monthly": 1}
    periods = freq_map.get(frequency, 1)
    amount_per_period = monthly_budget / periods

    # Generate next purchase dates
    today = datetime.now()
    if frequency == "monthly":
        dates = [today + timedelta(days=30*i) for i in range(min(6, months_ahead))]
    # ... etc
Enter fullscreen mode Exit fullscreen mode

Full Source Code

The complete script is ~200 lines. Get it here:

DCA Crypto Bot Python — €14.99 on Gumroad

Includes:

  • dca_bot.py — full source with all 4 features
  • README.md — installation and usage guide
  • Python 3.6+ compatible, zero dependencies

What I Would Add Next

If I extend this tool:

  • Live price fetching via CoinGecko public API (no auth needed)
  • CSV export for your purchase history
  • Multi-currency support (USD, GBP, CHF)
  • Rebalancing calculator for multi-crypto portfolios

The architecture makes it easy — each feature is an isolated function.

Key Takeaways

  1. DCA is the simplest, most battle-tested crypto strategy for non-traders
  2. Your tools should be local-first — your financial data belongs to you
  3. 200 lines of Python stdlib is often all you need
  4. The best investment tool is one you actually use

Also built: a Risk/Reward Calculator in Python — same philosophy, different use case.

Top comments (0)