Modern, real-time trading dashboard built with Next.js 15 and TypeScript for automated trading strategies.
This is the frontend application for the Fortified Trading Platform, providing a responsive web interface for monitoring and controlling automated trading strategies. The application uses WebSocket connections for real-time updates of trading status, positions, and trade history.
- Real-time Updates: WebSocket-based live data for trading status, positions, and trades
- Multi-Strategy Support: Monitor and control EMA, Supertrend, and ZeroDay strategies
- Live Trading Dashboard: View active positions, P&L, and trading metrics
- Trade History: Paginated view of paper and real trades
- Live Charts: Real-time candlestick charts with technical indicators
- Broker Integration: Manage Schwab and TastyTrade broker connections
- Paper & Live Trading: Switch between simulated and real trading modes
- Responsive Design: Mobile-friendly interface with dark mode support
- Framework: Next.js 15 (App Router with Turbopack)
- Language: TypeScript
- Styling: Tailwind CSS + shadcn/ui components
- State Management: React Context API
- Real-time: WebSocket connections via native WebSocket API
- Animations: Framer Motion
- Charts: Lightweight Charts (TradingView)
- Node.js 18+
- Backend API running on port 8000
- Redis for WebSocket pub/sub
# Install dependencies
npm install
# Run development server
npm run devThe application will be available at http://localhost:3000
# Build for production
npm run build
# Start production server
npm startThe frontend maintains persistent WebSocket connections for each trading strategy:
- Connection:
wss://[host]/api/ws/trading/{strategy}?token={jwt} - Auto-reconnection: Exponential backoff (max 30s)
- Heartbeat: Ping/pong every 15 seconds
- Message Types:
initial_snapshot: Full state on connectstatus: Trading status updatestrade: New trade notifications
src/
├── app/ # Next.js app router pages
│ ├── dashboard/ # Main dashboard routes
│ │ ├── strategy-control/ # Strategy management
│ │ ├── charts/ # Live charts view
│ │ └── user-setting/ # User settings
│ └── login/ # Authentication
├── components/ # React components
│ ├── ui/ # shadcn/ui components
│ ├── live-positions.tsx # Real-time positions table
│ ├── metrics-dashboard.tsx # Strategy metrics
│ ├── play-buttons.tsx # Start/stop controls
│ └── trades-table.tsx # Trade history
├── context/ # React Context providers
│ ├── AuthContext.tsx # Authentication state
│ └── TradingContext.tsx # Trading data & WebSocket
├── hooks/ # Custom React hooks
│ ├── use-websocket-trading.ts # WebSocket connection
│ └── use-trades.ts # Trade history
└── lib/ # Utilities and types
TradingContext: Manages global trading state
- WebSocket connections for all strategies
- Strategy status (running, symbols, uptime)
- Live/paper trading mode
- Broker connection status
AuthContext: Handles user authentication
- JWT token management
- User session persistence
- Protected route guards
Create a .env.local file:
# Not currently required - API URL is inferred from request origin
# NEXT_PUBLIC_API_URL=http://localhost:8000The frontend automatically proxies API requests to the backend at localhost:8000 in development.
GET /api/start-trading- Start strategyGET /api/stop-trading- Stop strategyGET /api/positions- Get active positionsGET /api/trades- Get trade history (paginated)POST /api/refresh-token-link- Update Schwab token
WS /api/ws/trading/{strategy}- Real-time strategy updates
Note: The old REST polling endpoint (/api/trading-status) is deprecated. All status updates now use WebSockets.
- App Router: Next.js 15 app directory with server/client components
- Turbopack: Fast incremental builds (enabled by default)
- Client Components: Marked with
"use client"directive - API Proxy: Next.js rewrites API calls to backend
- TypeScript strict mode
- ESLint for code quality
- Functional components with hooks
- Context for global state
- Custom hooks for reusable logic
# Start with PM2
pm2 start ecosystem.config.js --only frontend
# View logs
pm2 logs frontend
# Restart
pm2 restart frontend- Backend must be accessible at
localhost:8000 - Nginx proxies
/api/*and/api/ws/*to backend - Frontend serves on port 3000 (proxied via Nginx)
The application was migrated from REST polling to WebSocket-based real-time updates:
- Before: Polled
/api/trading-statusevery 5 seconds - After: Persistent WebSocket connections with push updates
- Benefits: Reduced server load, instant updates, better scalability
Components using WebSocket:
use-websocket-trading.ts- Main WebSocket hookTradingContext.tsx- Global WebSocket integrationlive-positions.tsx- Real-time position updatesmetrics-dashboard.tsx- Live metrics display
Check browser console for:
[WebSocket] ✅ Connected for strategy: ema
[WebSocket] ✅ Received initial snapshot
If connections fail:
- Verify backend is running
- Check JWT token is valid
- Ensure Redis is running (backend dependency)
Clear browser cache and reload:
- Chrome/Edge:
Ctrl + Shift + R(Windows) /Cmd + Shift + R(Mac) - Firefox:
Ctrl + F5/Cmd + Shift + R
This is a private trading platform. Follow existing code patterns:
- Use TypeScript types for all props/data
- Create reusable hooks for complex logic
- Keep components focused and testable
- Use shadcn/ui for consistent styling
Proprietary - All rights reserved