A full-stack real-time stock monitoring application with algorithmic analysis for Indian stock markets. Built with Spring Boot (backend) and React + Vite + Tailwind CSS (frontend).
- Real-Time Stock Monitoring: Live price updates via WebSocket
- Algorithmic Analysis:
- Sliding Window: Trend detection and volatility analysis
- Greedy Algorithm: Profit/loss threshold alerts
- Dynamic Programming: Optimal trading strategy calculation
- Personalized Alerts: Customizable profit targets and stop-loss levels
- Interactive Dashboard: Real-time charts with Chart.js
- Mock Data Mode: Development-friendly with realistic price simulations
- Premium UI: Modern, responsive design with Tailwind CSS
/stock_market
ββ backend/ # Spring Boot application
β ββ src/main/java/com/stockmonitor/
β β ββ Application.java
β β ββ controller/ # REST API endpoints
β β ββ service/ # Business logic & algorithms
β β ββ model/ # Data models
β β ββ util/ # API fetcher & utilities
β β ββ config/ # WebSocket & CORS config
β ββ pom.xml
ββ frontend/ # React + Vite application
ββ src/
β ββ components/ # React components
β ββ services/ # API & WebSocket services
β ββ App.jsx
ββ package.json
- Java: JDK 17 or higher
- Maven: 3.6+ (for building backend)
- Node.js: 18+ (for frontend)
- npm: 9+ (included with Node.js)
-
Navigate to the backend directory:
cd backend -
Build the project:
mvn clean install
-
Run the application:
mvn spring-boot:run
The backend will start on
http://localhost:8080
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the development server:
npm run dev
The frontend will start on
http://localhost:5173
Create a .env file in the project root (optional):
# API Configuration
TWELVE_DATA_API_KEY=your_api_key_here
# Mock Mode (true for development, false for live API)
USE_MOCK_DATA=true
# Fetch Interval (seconds)
FETCH_INTERVAL_SECONDS=30Mock Mode (Default - Recommended for Development):
- Set
USE_MOCK_DATA=trueinapplication.properties - Generates realistic price fluctuations
- No API calls, no rate limits
- Perfect for development and testing
Live Mode (Production):
- Set
USE_MOCK_DATA=false - Requires Twelve Data API key
- Free tier: 800 calls/day, 8 calls/min
- Get your API key: https://twelvedata.com/
Purpose: Real-time trend detection and volatility analysis
// Maintains last N prices in a deque
Deque<Double> priceWindow = new ArrayDeque<>();
// On each price update:
priceWindow.addLast(currentPrice);
if (priceWindow.size() > windowSize) {
priceWindow.removeFirst();
}
// Compute statistics
min = Collections.min(priceWindow);
max = Collections.max(priceWindow);
volatility = max - min;
trend = calculateTrend(priceWindow); // RISING/FALLING/STABLEKey Features:
- O(1) insertion and deletion
- Configurable window size (default: 20 prices)
- Real-time trend detection
Purpose: Immediate profit/loss alert generation
// Check profit target
if (currentPrice >= buyPrice + targetProfit) {
notifyUser("Target profit reached!");
}
// Check stop loss
if (currentPrice <= buyPrice - stopLoss) {
notifyUser("Stop loss hit!");
}Key Features:
- O(1) threshold checking
- Prevents duplicate alerts
- Customizable risk levels
Purpose: Calculate optimal trading strategy from historical data
// dp[i][k] = max profit using first i prices with k transactions
int[][] dp = new int[n+1][maxTransactions+1];
for (int t = 1; t <= maxTransactions; t++) {
int maxDiff = -prices[0];
for (int d = 1; d < n; d++) {
dp[d][t] = Math.max(dp[d-1][t], prices[d] + maxDiff);
maxDiff = Math.max(maxDiff, dp[d-1][t-1] - prices[d]);
}
}Key Features:
- O(n*k) time complexity
- Optimal profit calculation
- Support for multiple transactions
GET /api/stocks?symbol={SYMBOL}Returns current price, history, and window analysis.
POST /api/monitor
Content-Type: application/json
{
"symbol": "RELIANCE.NSE",
"buyPrice": 2500.00,
"targetProfit": 50.00,
"stopLoss": 30.00,
"riskLevel": "MEDIUM"
}DELETE /api/monitor/{symbol}GET /api/monitorGET /api/notificationsDELETE /api/notificationsGET /api/analysis/{symbol}?transactions=5Returns optimal profit calculation with specified number of transactions.
-
Start Both Servers:
- Backend:
mvn spring-boot:run(port 8080) - Frontend:
npm run dev(port 5173)
- Backend:
-
Open Dashboard: Navigate to
http://localhost:5173 -
Select a Stock: Choose from popular Indian stocks (e.g., RELIANCE.NSE)
-
Set Thresholds:
- Buy Price: βΉ2500
- Target Profit: βΉ50
- Stop Loss: βΉ30
- Risk Level: MEDIUM
-
Start Monitoring: Click "Start Monitoring π"
-
Watch Real-Time Updates:
- Price chart updates every 30 seconds
- Green line = Target profit
- Red line = Stop loss
- Trend indicators (RISING/FALLING/STABLE)
-
Receive Alerts: Notifications appear when thresholds are hit
- Dark Mode Design: Premium dark theme with gradients
- Responsive Layout: Works on desktop, tablet, and mobile
- Real-Time Charts: Smooth animations with Chart.js
- Color-Coded Alerts:
- π’ Green: Profit alerts
- π΄ Red: Loss alerts
- π΅ Blue: Info alerts
- Live Connection Status: WebSocket indicator
- Browser Notifications: Desktop alerts (if permitted)
cd backend
mvn testcd frontend
npm run build- Start backend in mock mode
- Start frontend
- Monitor a stock (e.g., RELIANCE.NSE)
- Observe price fluctuations and alerts
- Test threshold triggers by adjusting values
Popular Indian stocks supported (mock mode):
RELIANCE.NSE- Reliance IndustriesTCS.NSE- Tata Consultancy ServicesINFY.NSE- InfosysHDFCBANK.NSE- HDFC BankICICIBANK.NSE- ICICI BankWIPRO.NSE- WiproSBIN.NSE- State Bank of IndiaITC.NSE- ITC Limited
Port 8080 already in use:
# Change port in application.properties
server.port=8081WebSocket connection failed:
- Ensure CORS is properly configured
- Check firewall settings
- Verify backend is running
Dependencies not installing:
# Clear cache and reinstall
rm -rf node_modules package-lock.json
npm installWebSocket not connecting:
- Check backend is running on port 8080
- Verify proxy configuration in
vite.config.js - Check browser console for errors
mvn clean package
java -jar target/stock-monitoring-backend-1.0.0.jarnpm run build
# Deploy dist/ folder to your hosting serviceBackend:
- β Java 17
- π Spring Boot 3.2.0
- π Spring WebSocket
- π Spring Scheduler
- π Jackson (JSON)
Frontend:
- βοΈ React 18
- β‘ Vite 5
- π¨ Tailwind CSS 3
- π Chart.js 4
- π STOMP WebSocket
- π‘ Axios
This project is for educational purposes.
Built by Trisha Dabral.
Happy Trading! ππ°