a96bbe4d2a35d62f5909dab76f027fb8f3ef5442
Portfolio Tracker
A comprehensive portfolio management application built with Go that allows users to track their investment portfolios across multiple currencies with real-time data integration.
🚀 Features
Portfolio Management
- Multiple Portfolios: Create and manage multiple investment portfolios
- Multi-Currency Support: Track investments in different currencies with automatic conversion
- Transaction Tracking: Record buy, sell, and dividend transactions
- Real-time Data: Integration with Yahoo Finance API for live stock prices and data
Currency Conversion
- Automatic Currency Detection: Automatically detects stock currencies from Yahoo Finance
- Real-time Exchange Rates: Fetches current exchange rates from
exchangerate-api.com - Smart Caching: 1-hour cache for exchange rates to optimize performance
- 160+ Currencies Supported: Including major currencies like USD, EUR, GBP, JPY, CHF
User Experience
- User Authentication: Secure registration and login system
- Responsive Design: Clean, modern UI built with Tabler CSS framework
- Stock Search: Advanced search functionality for stocks and securities
- Interactive Charts: Stock price and dividend charts powered by ApexCharts
- Transaction Management: Edit and delete transactions with full audit trail
🛠️ Technology Stack
- Backend: Go 1.24.4
- Database: SQLite with GORM ORM
- Templates: Templ templating engine
- Frontend: Tabler CSS framework
- Charts: ApexCharts
- APIs: Yahoo Finance, ExchangeRate API
- Session Management: Gorilla Sessions
📋 Prerequisites
- Go 1.24.4 or later
- Git
🔧 Installation
- Clone the repository:
git clone <repository-url>
cd portfolio-tracker
- Install dependencies:
go mod download
- Install Templ CLI (for template generation):
go install github.com/a-h/templ/cmd/templ@latest
- Generate templates (if needed):
templ generate
- Run the application:
go run cmd/app/main.go
- Access the application:
Open your browser and navigate to
http://localhost:8080
📁 Project Structure
portfolio-tracker/
├── cmd/app/main.go # Application entry point
├── internal/
│ ├── handler/ # HTTP handlers
│ │ ├── api.go # API endpoints
│ │ ├── auth.go # Authentication handlers
│ │ ├── portfolio.go # Portfolio management
│ │ └── pages.go # Page handlers
│ ├── model/ # Database models
│ │ ├── user.go # User model
│ │ ├── portfolio.go # Portfolio model
│ │ ├── activities.go # Transaction model
│ │ └── models.go # Yahoo Finance response models
│ ├── util/ # Utility functions
│ │ ├── currency.go # Currency conversion utilities
│ │ └── yahoo-utils.go # Yahoo Finance API utilities
│ ├── session/ # Session management
│ └── web/templates/ # Templ templates
├── docs/ # Documentation
├── data/ # SQLite database (auto-created)
├── go.mod # Go module file
└── README.md # This file
🎯 Usage
Getting Started
- Register an Account: Create a new user account or login with existing credentials
- Create a Portfolio: Set up your first portfolio with a name, base currency, and description
- Add Transactions: Start tracking your investments by adding buy, sell, or dividend transactions
- Search Stocks: Use the search functionality to find stocks and add them to your portfolio
- Monitor Performance: View your portfolio summary and track performance across currencies
Currency Conversion
The application automatically:
- Detects the currency of stocks from Yahoo Finance
- Converts transaction amounts to your portfolio's base currency
- Displays both original and converted amounts for transparency
- Updates exchange rates hourly for accuracy
Stock Data
- Real-time Prices: Current stock prices and market data
- Historical Charts: Price movement over time
- Dividend History: Track dividend payments and history
- Company Information: Basic company details and metrics
🔑 API Endpoints
Public Endpoints
GET /- DashboardPOST /user/register- User registrationPOST /user/login- User loginPOST /user/logout- User logout
Portfolio Management
GET /portfolio/{id}- View portfolio detailsPOST /portfolio/create- Create new portfolioPOST /portfolio/transaction- Add transactionPOST /portfolio/transaction/edit- Edit transactionPOST /portfolio/transaction/delete- Delete transaction
API Endpoints
GET /api/yahoo- Get stock data from Yahoo FinanceGET /api/stocksearch- Search for stocksGET /api/yahoomaxdividends- Get dividend dataPOST /api/admin/clear-currency-cache- Clear currency cacheGET /api/admin/currency-cache-info- Get cache information
🌍 Currency Support
The application supports 160+ currencies including:
| Currency | Code | Symbol |
|---|---|---|
| US Dollar | USD | $ |
| Euro | EUR | € |
| British Pound | GBP | £ |
| Japanese Yen | JPY | ¥ |
| Swiss Franc | CHF | CHF |
| Canadian Dollar | CAD | C$ |
| Australian Dollar | AUD | A$ |
| And many more... |
🚦 Development
Running Tests
go test ./internal/util/ -v
Generating Templates
templ generate
Database
The application uses SQLite and automatically creates the database file at data/portfolio.db on first run. Database migrations are handled automatically by GORM.
📊 Features in Detail
Multi-Currency Portfolio Management
- Create portfolios in different base currencies
- Automatic currency conversion for cross-currency transactions
- Real-time exchange rate fetching and caching
- Clear indication of converted vs. original amounts
Transaction Management
- Support for Buy, Sell, and Dividend transactions
- Automatic stock currency detection
- Edit and delete capabilities
- Transaction history and audit trail
Stock Integration
- Yahoo Finance API integration
- Real-time stock prices and data
- Stock search functionality
- Price and dividend charts
- Company information display
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 External APIs
- Yahoo Finance: Stock data, prices, and company information
- ExchangeRate API: Currency exchange rates (free tier, no API key required)
⚠️ Disclaimer
This application is for educational and personal use only. Stock prices and financial data are provided for informational purposes. Always consult with financial professionals before making investment decisions.
Description
Languages
Go
61.9%
templ
38.1%