How patan4ik/kraken-portfolio-tracker works
Purpose and Entrypoints
Kraken Portfolio Tracker is a Python 3.11+ CLI application for fetching Kraken account data, persisting it locally, and generating offline portfolio and ledger analysis. Primary entrypoints are start.py for setup/basic refresh and update.py for validated incremental ledger updates plus downstream recomputation. Report modules can also be invoked directly under src/.
Kraken Access and Credential Boundary
src/api.py encapsulates interaction with the external Kraken API for live balances, prices, and ledger retrieval. Credentials are resolved separately by src/keys.py, supporting system keyring, local key file, or environment variables. src/config.py centralizes runtime locations/settings, keeping API secrets and provider access outside analytical modules.
Ledger Ingestion and Durable Cache
src/ledger_loader.py incrementally downloads Kraken ledger pages/date ranges and maintains the raw local ledger cache. src/storage.py is the persistence boundary: SQLite holds normalized/full ledger payloads in balances_history/ledger.db, while JSON and CSV files support caching and exports. The intended steady-state reporting path is SQLite, not live API calls.
Balance Snapshot Pipeline
src/balances.py obtains current balances and prices, aggregates available and staked holdings, and writes daily portfolio snapshots/history. This live-data path feeds reconciliation and complements the historical ledger database; it is distinct from ledger-derived cost-basis calculation.
Update Orchestration and Validation
update.py plans missing ledger date ranges, supports dry runs and paging/rate-delay controls, then coordinates ingestion, balance refresh, summary generation, and reconciliation. src/validators.py performs preflight validation of database/schema/API-key conditions before mutation. start.py provides the simpler initial workflow, key setup, snapshot refresh, and optional ledger update.
Portfolio Analytics and Reconciliation
src/portfolio_summary.py recomputes FIFO/average cost basis from the complete stored ledger each run, normalizing Kraken wallet suffixes and excluding internal transfers. It also derives EMA/trend-based forecasts. src/balance_reconciliation.py compares ledger-derived holdings with the current balance snapshot and writes tolerance-based mismatch results. Core outputs are materialized as local CSV artifacts rather than served over a network.
Report Generation
SQLite-backed reporting is partitioned by analysis use case: EUR spend aggregation in src/ledger_eur_report.py, acquisitions in src/ledger_asset_report.py, and disposals/proceeds/fees in src/ledger_sell_report.py. src/portfolio_summary_report.py converts computed portfolio metrics into enriched sell-target, trend, risk, and signal CSV output.
Runtime and Delivery
The runtime is local Python with SQLite, filesystem CSV/JSON caches, optional OS credential keyring, and the Kraken API as the sole stated external service. GitHub Actions workflows under .github/workflows/ provide CI. Windows distribution packages start.py and update.py as PyInstaller executables; no web server or hosted application infrastructure is indicated.
Main entry points: update.py Incremental update CLI · start.py Initial setup CLI · balances.py Balance snapshot pipeline · storage.py Persistence boundary
Components 20
CLI Workflows
- Initial setup CLI · Sets up keys, refreshes snapshots, and can start a ledger update.
start.py - Incremental update CLI · Validates, plans ledger gaps, and runs downstream recomputation.
update.py
Access & Validation
- Preflight validation · Checks database, schema, and API-key conditions before mutation.
src/validators.py - Runtime configuration · Centralizes local locations and runtime settings.
src/config.py - Credential resolver · Loads Kraken credentials from keyring, file, or environment.
src/keys.py - Kraken API client · Retrieves live balances, prices, and ledger data.
src/api.py
Data Ingestion & Storage
- Incremental ledger loader · Downloads paged ledger ranges into the local cache.
src/ledger_loader.py - Balance snapshot pipeline · Aggregates available and staked holdings with current prices.
src/balances.py - Persistence boundary · Manages SQLite ledger data plus JSON and CSV caches.
src/storage.py - Ledger database · Durable normalized and full Kraken ledger payloads.
- Snapshot history · Daily portfolio snapshots and cache artifacts.
Analytics & Reports
- Portfolio recomputation · Calculates cost basis, holdings, and EMA/trend forecasts from stored ledger data.
src/portfolio_summary.py - Balance reconciliation · Compares ledger-derived holdings against current snapshots.
src/balance_reconciliation.py - EUR spend report
src/ledger_eur_report.py - Acquisitions report
src/ledger_asset_report.py - Disposals report
src/ledger_sell_report.py - Portfolio signals report · Produces enriched sell-target, trend, risk, and signal CSVs.
src/portfolio_summary_report.py - Offline CSV outputs · Local analysis, report, and reconciliation outputs.
Delivery
- GitHub Actions CI
- Windows executables · Packages the two CLI entrypoints for Windows.
Connections 30
- Initial setup CLI → Credential resolver: sets up credentials
- Initial setup CLI → Balance snapshot pipeline: refreshes
- Initial setup CLI → Incremental update CLI: optionally invokes
- Incremental update CLI → Preflight validation: preflight
- Incremental update CLI → Incremental ledger loader: plans and runs
- Incremental update CLI → Balance snapshot pipeline: refreshes
- Incremental update CLI → Portfolio recomputation: recomputes
- Incremental update CLI → Balance reconciliation: runs
- Runtime configuration → Credential resolver: configures locations
- Credential resolver → Kraken API client: supplies credentials
- Incremental ledger loader → Kraken API client: fetches ledger pages
- Incremental ledger loader → Persistence boundary: persists
- Balance snapshot pipeline → Kraken API client: fetches balances and prices
- Balance snapshot pipeline → Persistence boundary: writes snapshots
- Persistence boundary → Ledger database: stores ledger
- Persistence boundary → Snapshot history: writes cache/history
- Ledger database → Portfolio recomputation: complete ledger
- Ledger database → EUR spend report: query source
- Ledger database → Acquisitions report: query source
- Ledger database → Disposals report: query source
- Portfolio recomputation → Balance reconciliation: ledger-derived holdings
- Snapshot history → Balance reconciliation: current snapshot
- Portfolio recomputation → Portfolio signals report: portfolio metrics
- Balance reconciliation → Offline CSV outputs: mismatches
- EUR spend report → Offline CSV outputs: exports
- Acquisitions report → Offline CSV outputs: exports
- Disposals report → Offline CSV outputs: exports
- Portfolio signals report → Offline CSV outputs: exports
- Windows executables → Initial setup CLI: packages
- Windows executables → Incremental update CLI: packages