A modern, real-time stock portfolio management application built with ASP.NET Core and Next.js
CandleWise has evolved from a simple stock price tracker into a comprehensive Portfolio Management System that helps users track their investments, monitor performance, and manage their stock portfolios with real-time market data.
- Real-time Portfolio Tracking - Monitor your investments with live stock prices
- Holdings Management - Add, edit, and remove stocks from your portfolio
- Performance Analytics - Track gains/losses, allocation percentages, and portfolio growth
- Net Worth Dashboard - Get a quick overview of your total portfolio value
- Live Market Data - Real-time stock prices from Alpaca Markets API
- Gain/Loss Calculations - Automatic calculation of performance metrics
- Portfolio Allocation - Visual breakdown of your investment distribution
- Transaction History - Keep track of all your buy/sell activities
CandleWise/
โโโ ๐ง backend/ # ASP.NET Core 8 Web API
โโโ ๐จ frontend/ # Next.js 14 with TypeScript
โโโ ๐ shared/ # Shared TypeScript definitions
โโโ ๐ณ docker-compose.yml
โโโ ๐ scripts/ # Development helpers
- .NET 8.0 SDK
- Node.js 18+
- Docker (optional)
-
Clone the repository
git clone https://github.com/pedropcamellon/CandleWise.git cd CandleWise -
Install dependencies
npm install
-
Setup environment variables
cp .env.example .env # Edit .env to configure your Alpaca API credentials -
Start development servers
npm run dev
This will start:
- Backend: http://localhost:5000 (API + Swagger)
- Frontend: http://localhost:3000
PowerShell script to set up Azure resources for CandleWise deployment
# Start the entire stack
npm run docker:up
# Stop the stack
npm run docker:down- โ RESTful Web API
- โ Real-time stock data from Alpaca Markets
- โ HttpClientFactory for efficient HTTP calls
- โ Swagger/OpenAPI documentation
- โ CORS configuration for frontend
- โ Docker containerization
- โ Modern React with TypeScript
- โ Tailwind CSS for styling
- โ Real-time stock price dashboard
- โ Responsive design
- โ API integration with backend
- โ Docker containerization
- โ TypeScript type definitions
- โ Consistent data models
- โ Monorepo structure
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/stock |
Get all stocks with current prices |
| GET | /api/stock/{symbol}/price |
Get current price for specific stock |
| Command | Description |
|---|---|
npm run dev |
Start both backend and frontend |
npm run dev:backend |
Start only backend |
npm run dev:frontend |
Start only frontend |
npm run build |
Build both applications |
npm run test |
Run all tests |
npm run docker:up |
Start Docker stack |
npm run docker:down |
Stop Docker stack |
The frontend features a responsive stock dashboard that:
- ๐ Displays real-time stock prices
- ๐ Allows manual price refresh
- ๐จ Clean, modern UI with Tailwind CSS
- ๐ฑ Mobile-responsive design
The system integrates with Alpaca Markets API to fetch real-time stock data:
- Real-time price updates
- Historical data support
- Professional trading data
- Secure API key management
Complete containerization with:
- Multi-stage builds for optimization
- Development and production configurations
- Docker Compose for orchestration
- Hot reloading in development
- API keys stored in environment variables
- CORS properly configured
- No sensitive data in client-side code
- Docker security best practices
- Set production environment variables
- Build the applications:
npm run build - Deploy using Docker:
docker-compose up -d
- Backend: Azure App Service
- Frontend: Azure Static Web Apps or App Service
- Container Registry: Azure Container Registry
CandleWise now uses the Alpaca Market Data API to provide real-time and historical stock prices. This integration replaces mock data with live market information.
- Visit Alpaca Markets and create a free account
- Navigate to the API section in your dashboard
- Generate your API Key ID and Secret Key
For development, create backend/.env.local:
# Alpaca Market Data API Configuration
ALPACA__APIKEYID=YOUR_API_KEY_ID
ALPACA__APISECRETKEY=YOUR_API_SECRET_KEY
ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_URLS=http://localhost:5245Or add to backend/appsettings.Development.json:
{
"Alpaca": {
"BaseUrl": "https://data.alpaca.markets",
"ApiKeyId": "YOUR_API_KEY_ID",
"ApiSecretKey": "YOUR_API_SECRET_KEY"
}
}NEXT_PUBLIC_API_URL=/api
DOTNET_API_URL=http://localhost:5245/api
NODE_ENV=development- Purpose: Secure HTTP client service for Alpaca API calls
- Features:
- Real-time quote fetching
- Batch price requests for performance
- Historical data retrieval
- Comprehensive error handling and logging
- Rate limiting protection
- Endpoints:
GET /api/stock- Fetches all tracked stocks with live pricesGET /api/stock/{symbol}/price- Single stock price lookupGET /api/stock/{symbol}/historical- Historical price data
- Features:
- Real-time portfolio tracking with live price updates
- Individual holding cards with optimized state management
- Visual price direction indicators (โโ)
- Automatic 30-second price refresh for each holding
- Flash effects for price changes with ring animations
- Manual refresh buttons with loading states
- Performance calculations and gain/loss tracking
- Interactive stock charts with historical data
- Memoized components to prevent unnecessary re-renders
- Efficient useCallback hooks for optimized performance
- Background price updates without blocking UI
- Comprehensive error handling for API credentials
- Source: IEX Exchange (Free tier)
- Update Frequency: Every 5 seconds
- Data Points: Bid/Ask prices, timestamps
- Timeframes: Daily bars
- Range: Since 2016
- Usage: Chart visualization and trend analysis
- API Calls: 200 per minute
- Websocket Subscriptions: 30 symbols
- Real-time Coverage: IEX exchange only
- Historical Access: Last 15 minutes delay
- Batch Requests: Fetch multiple stock prices in single API call
- Caching: Background updates preserve existing data on errors
- Error Handling: Graceful degradation when API limits are reached
- Connection Pooling: Reuse HTTP connections for better performance
- Keys stored in configuration files (development)
- Environment variables recommended for production
- No hardcoded credentials in source code
- Secure HTTP client configuration
- Comprehensive logging for debugging
- User-friendly error messages
- Automatic retry logic for transient failures
- Fallback to cached data when API is unavailable
- Live Price Indicators: Green pulsing dots show real-time data
- Update Status: Visual feedback during price updates
- Timestamp Display: Shows last successful update time
- Error Recovery: Retry buttons for failed requests
- Portfolio value updated every 5 seconds
- Gain/loss calculations using live prices
- Allocation percentages recalculated automatically
- Top performer tracking with real-time rankings
# Backend (ASP.NET Core)
cd backend
dotnet run
# Frontend (Next.js)
cd frontend
npm run dev- Check browser console for API call logs
- Monitor backend logs for Alpaca API responses
- Watch for rate limit warnings
- Complete Market Coverage: All US exchanges
- Unlimited Websockets: No symbol restrictions
- Higher Rate Limits: 10,000 API calls per minute
- Real-time Data: No 15-minute delay
- Options Data: OPRA feed access
Error: Unauthorized (401)
Solution: Verify API keys are correctly set in configuration
Error: Too Many Requests (429)
Solution: Implement backoff strategy or upgrade to paid plan
Warning: No quote data found for symbol
Solution: Check if symbol exists and market is open
- Verify API keys in appsettings.json
- Check network connectivity to data.alpaca.markets
- Monitor browser console for frontend errors
- Review backend logs for API response details
{
"quotes": {
"AAPL": {
"ap": 175.50,
"bp": 175.45,
"as": 100,
"bs": 200,
"t": "2025-08-01T20:30:00Z"
}
}
}{
"bars": {
"AAPL": [
{
"c": 175.43,
"h": 176.10,
"l": 174.80,
"o": 175.00,
"t": "2025-08-01T04:00:00Z",
"v": 50000000,
"vw": 175.25
}
]
}
}- Real-time Portfolio Tracking: Live market values
- Accurate Performance Metrics: Based on actual market prices
- Professional Grade Data: Same data used by financial institutions
- Historical Analysis: Trend tracking and performance visualization
- Reliable Data Source: Enterprise-grade market data API
- Comprehensive Coverage: Stocks, ETFs, and options
- Developer-Friendly: RESTful API with clear documentation
- Scalable Architecture: Built to handle high-frequency updates
- WebSocket integration for instant price updates
- Real-time alerts and notifications
- Advanced charting with technical indicators
- Crypto currency support
- International markets integration
- Forex and commodities data
- Portfolio optimization suggestions
- Risk analysis and metrics
- Performance benchmarking
- Create
backend/appsettings.Local.json(this file is git-ignored):
{
"Alpaca": {
"ApiKeyId": "YOUR_ACTUAL_API_KEY_ID",
"ApiSecretKey": "YOUR_ACTUAL_API_SECRET_KEY"
}
}- Get your free Alpaca API keys:
- Visit: https://alpaca.markets/
- Create free account
- Go to API section
- Generate Paper Trading keys (free tier)
Use environment variables instead of files:
ALPACA__APIKEYID=your_key_id
ALPACA__APISECRETKEY=your_secret_keydocker run -e ALPACA__APIKEYID=your_key_id -e ALPACA__APISECRETKEY=your_secret_key candlewise-backend# PowerShell
$env:ALPACA__APIKEYID="your_key_id"
$env:ALPACA__APISECRETKEY="your_secret_key"
# Command Prompt
set ALPACA__APIKEYID=your_key_id
set ALPACA__APISECRETKEY=your_secret_key- Environment variables
appsettings.Local.json(development only)appsettings.Development.jsonappsettings.json
- โ NEVER commit API keys to Git
- โ
DO use
appsettings.Local.jsonfor development - โ DO use environment variables for production
- โ DO regenerate keys if accidentally exposed
- โ DO use Paper Trading keys for development
Run this command to verify your setup:
dotnet run --urls=http://localhost:5245Then test the API:
curl http://localhost:5245/api/stock# Navigate to backend
cd backend
# Copy your API keys to local config
echo '{"Alpaca":{"ApiKeyId":"YOUR_KEY","ApiSecretKey":"YOUR_SECRET"}}' > appsettings.Local.json
# Run the application
dotnet run --urls=http://localhost:5245Ready to experience live market data in your portfolio management system! ๐
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License.
Built with โค๏ธ by Pedro PC Amellon