Skip to content

Praveenms13/CryptoPortfolioTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βœ… Crypto Portfolio Tracker (Spring Boot Backend)

A backend application that helps users manage and monitor their cryptocurrency investments. Users can track their coin holdings, view real-time prices, calculate profit/loss, and set up price alerts.


🎯 Objective

To build a secure and user-friendly backend system where individuals can:

  • Add, edit, and delete cryptocurrency holdings
  • Track real-time prices using third-party APIs (e.g., CoinGecko)
  • View profit/loss calculations for individual coins and total portfolio
  • Get alerts when coins hit specific price thresholds

🧩 Core Features (Explained Simply for Freshers)

πŸ” 1. User Authentication Module

Purpose: Protect user data and allow secure access.
Functionalities:

  • βœ… Register and Login functionality
  • βœ… Basic authentication using session_token
  • βœ… Each user sees only their holdings

What You’ll Learn:

  • How Spring Security works
  • Securing API routes using roles
  • Session management and validation

πŸ“ˆ 2. Holdings Management Module

Purpose: Allow users to record and manage their crypto investments.
Functionalities:

  • Add new holdings:
    • Coin Symbol (e.g., BTC)
    • Quantity (how much they own)
    • Buy Price (price when bought)
  • Edit and Delete entries
  • View current portfolio

What You’ll Learn:

  • Building CRUD APIs with Spring Boot
  • Using JPA for database operations
  • Filtering user-specific data

🌐 3. Real-Time Price Fetcher

Purpose: Keep prices up to date using real market data.
Functionalities:

  • Integrate with CoinGecko or similar public APIs
  • Fetch latest prices every 5–10 minutes using @Scheduled
  • Store prices in a local database or in-memory

What You’ll Learn:

  • Making REST API calls with RestTemplate
  • Using @Scheduled to run background tasks
  • Parsing and mapping JSON to Java objects using Jackson
  • Database design for price history

πŸ“Š 4. Gain/Loss Calculator

Purpose: Show how each holding is performing.
Functionalities:

  • For each coin, calculate:
    • gain = (currentPrice - buyPrice) * quantity
    • percentageChange = (gain / (buyPrice * quantity)) * 100
  • Show total portfolio profit/loss

What You’ll Learn:

  • Writing business logic in service layers
  • Performing math operations in Java
  • Sending calculated results via REST APIs

πŸ”” 5. Price Alert Module

Purpose: Notify users when their coin hits a target price.
Functionalities:

  • Users can set a price alert (e.g., ETH > $3,000)
  • The system checks prices on each cron job
  • If the condition is met:
    • Mark the alert as β€œTriggered”
    • Optionally log it or send an email

What You’ll Learn:

  • Writing condition-based business logic
  • Storing and updating alert status
  • Optional: Logging or sending notifications

βš™οΈ Tech Stack Overview

Layer Technology
Language Java
Framework Spring Boot, Spring Data JPA
Security Spring Security, Basic authentication using session_token
Scheduler Spring Scheduler (@Scheduled)
REST Client RestTemplate / WebClient
JSON Parser Jackson
Database MySQL
Build Tool Maven

πŸ§ͺ API Module Overview

πŸ“Œ User Controller

  • POST /api/auth/register – Register a new user
  • POST /api/auth/login – Login and receive token
  • PUT /api/users/updateUser/{id} – Update user details
  • GET /api/users/getUser/{id} – Get user details by ID
  • GET /api/users/getId – Get currently logged-in user's ID

πŸ“Œ Holdings

  • GET /api/holdings/add – Add a new cryptocurrency holding
  • POST /api/holdings/getHoldings – Get current user's holdings
  • PUT /api/holdings/getMyNetValue – Get total portfolio value for current user

πŸ“Œ Price Alerts

  • POST /api/alert/create – Create a new price alert
  • GET /api/alert/user/{userid} – List all alerts
  • GET /api/alerts/user/{userid}/triggered – List all triggered alerts
  • PUT /api/alert/{id} – Update a price alert
  • PUT /api/alert/{id}/disable – Disable a specific alert
  • DELETE /api/alert/{id} – Delete a price alert

πŸ“Œ Admin Controller

  • POST /api/admin/login – Login as admin
  • GET /api/admin/users – View all users
  • GET /api/admin/user/{id} – Get user details by ID (admin access)

πŸ“Œ Crypto Controller

  • GET /api/crypto/getPrice/{symbol} – Get current price of a crypto by symbol
  • GET /api/crypto/getAllCryptos – Get list of all supported cryptocurrencies

Class Diagram

This diagram represents a stock portfolio management system with layers:
Controllers, DTO, Enum, Model, Repository, Services, and Entities.
It includes user authentication, alert generation, portfolio creation, and gain/loss calculation.
Entities like User, PriceAlert, Alert, Holding, and Log manage data and behavior.
Services like PriceService, AlertService, AlertSchedulerService, AdminService, CryptoService, CustomUserDetailsService, EmailService, HoldingService, NotificationService, and UserService provide business logic.


image

ER Diagram

This ER diagram models Users, Admins, Holdings, and Logs with relationships among them.

  • A User can have multiple Holdings and can generate multiple Logs when transactions occur.
  • Holdings store data about the cryptocurrencies owned, such as coin name, quantity, buy price, and price alerts.
  • Logs record detailed transaction history including buy/sell prices and dates.
  • An Admin can review logs but does not directly manage holdings or users.

image

Database Diagram

This database diagram models the core components of a Crypto Portfolio Tracker application, including users, holdings, transaction logs, and external coin data.
It consists of four main tables: users, holdings, logs, and coin_API.


image

🧠 Key Concepts for Freshers

Area What You’ll Learn
Spring Boot APIs Build and secure backend routes
Security Basic authentication login using session_token and access control
Scheduling Automate background tasks like price fetcher
API Integration Call real-world APIs using Java
JSON Handling Deserialize API responses with Jackson
Logic & Math Calculate gains, losses, and percentages
Alerts Apply business rules (if-else, comparisons)

πŸ—‚ Project Structure

com.example.CryptoPortfolioTracker
β”œβ”€β”€ config
β”‚ └── SecurityConfig.java
β”œβ”€β”€ controller
β”‚ β”œβ”€β”€ AdminController.java
β”‚ β”œβ”€β”€ AlertController.java
β”‚ β”œβ”€β”€ CryptoController.java
β”‚ β”œβ”€β”€ HoldingController.java
β”‚ └── UserController.java
β”œβ”€β”€ dto
β”‚ β”œβ”€β”€ AddHoldingRequest.java
β”‚ β”œβ”€β”€ AlertRequestDTO.java
β”‚ β”œβ”€β”€ SimpleUserResponse.java
β”‚ β”œβ”€β”€ CryptoData.java
β”‚ β”œβ”€β”€ LoginRequest.java
β”‚ β”œβ”€β”€ HoldingDTO.java
β”‚ └── RegisterRequest.java
β”œβ”€β”€ entity
β”‚ β”œβ”€β”€ Alert.java
β”‚ β”œβ”€β”€ Holding.java
β”‚ β”œβ”€β”€ Log.java
β”‚ └── User.java
β”œβ”€β”€ enums
β”‚ β”œβ”€β”€ AlertDirection.java
β”‚ β”œβ”€β”€ AlertStatus.java
β”‚ └── Role.java
β”œβ”€β”€ exception
β”‚ β”œβ”€β”€ GlobalExceptionHandler.java
β”‚ └── ResourceNotFoundException.java
β”œβ”€β”€ model
β”‚ └── ApiResponse.java
β”œβ”€β”€ repository
β”‚ β”œβ”€β”€ AlertRepository.java
β”‚ β”œβ”€β”€ HoldingRepository.java
β”‚ └── LogRepository.java
β”‚ └── UserRepository.java
β”œβ”€β”€ service
β”‚ β”œβ”€β”€ AdminService.java
β”‚ └── AlertSchedulerService.java
β”‚ β”œβ”€β”€ AlertService.java
β”‚ β”œβ”€β”€ CryptoService.java
β”‚ β”œβ”€β”€ EmailService.java
β”‚ β”œβ”€β”€ HoldingService.java
β”‚ β”œβ”€β”€ NotificationService.java
β”‚ β”œβ”€β”€ PriceService.java
β”‚ └── UserService.java
β”œβ”€β”€ CryptoPortfolioTrackerApplication.java
└── README.md

πŸš€ How to Run

βœ… Prerequisites

  • Java 17+
  • Maven
  • MySQL
  • Postman (for testing APIs)

πŸ§ͺ Steps

  1. Clone the project:
    git clone https://github.com/your-username/CryptoPortfolioTracker.git cd CryptoPortfolioTracker

  2. Create a database: CREATE DATABASE CryptoPortfolioTracker;

  3. Configure application.properties: spring.application.name=CryptoPortfolioTracker spring.datasource.url=jdbc:mysql://10.9.124.199:3306/CryptoPortfolioTracker?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true spring.datasource.username=root spring.datasource.password=password spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

    spring.mail.host=smtp-relay.brevo.com spring.mail.port=587 spring.mail.username=[email protected] spring.mail.password=h1nr2WQwZysT5zVg spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true

  4. Build and run: ./mvnw clean install ./mvnw spring-boot:run

  5. Test using Swagger or Postman.

πŸ“¦ Optional Enhancements

Feature Benefit
Graphical reports (charts) Easier to visualize performance
Export portfolio to PDF/Excel For offline record-keeping
Mobile app integration Future frontend possibilities
WebSocket price updates Live price tracking

πŸ‘©β€πŸ’» Contributors

Name Role
Praveen Project Lead, User Module, GlobalExceptionHandling Module, Basic authentication using session_token & Scheduler Logic
Aayushi Alert module
Kaushik, Harshnie Price Fetcher, Gain Calculator
Navya Fetch API Module
Lakshmi Bhanu Admin Module and Junit testing

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages