A full-stack trading application built with Go (backend) and React (frontend) featuring real-time price updates, order management, and WebSocket communication.
- Backend: Go with Gin framework, SQLite database
- Frontend: React 18 with Vite, Chart.js for price visualization
- Communication: REST API + WebSocket for real-time updates
trading-dashboard/
├── backend/
│ ├── cmd/server/main.go # Backend entry point
│ ├── internal/
│ │ ├── api/ # API routes and middleware
│ │ ├── models/ # Data models
│ │ ├── services/ # Business logic
│ │ └── websocket/ # WebSocket hub and clients
│ ├── go.mod # Go dependencies
│ └── Dockerfile
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Main app component
│ │ ├── components/ # React components
│ │ ├── api/ # API client functions
│ │ ├── hooks/ # Custom React hooks
│ │ └── main.jsx # React entry point
│ ├── package.json
│ ├── vite.config.js
│ └── Dockerfile
└── docker-compose.yml
cd backend
go run ./cmd/server/main.goThe backend will start on http://localhost:8080
Environment Variables (optional):
set JWT_SECRET=your-secret-key
set DB_PATH=./data/trading.db
set GIN_MODE=releaseOr on Linux/Mac:
export JWT_SECRET=your-secret-key
export DB_PATH=./data/trading.db
export GIN_MODE=release
go run ./cmd/server/main.goIn a new terminal:
cd frontend
npm install
npm run devThe frontend will start on http://localhost:5173
docker-compose up --build- Backend:
http://localhost:8080 - Frontend:
http://localhost:3000
POST /login- Login with username
Request:
{
"username": "trader1"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}GET /prices- Get current prices for all symbols
POST /orders- Place a new order (requires authentication)GET /orders- Get all ordersGET /orders/:id- Get specific orderPOST /orders/:id/cancel- Cancel an order (requires authentication)
GET /holdings- Get user holdings (requires authentication)
GET /ws- WebSocket connection for real-time price updates
- ✅ User authentication with JWT tokens
- ✅ Real-time price updates via WebSocket
- ✅ Place buy/sell orders
- ✅ View order history and status
- ✅ Track holdings and portfolio
- ✅ Interactive price charts
- ✅ Order cancellation
- ✅ CORS enabled for development
If port 8080 or 5173 is already in use:
Windows:
Get-NetTCPConnection -LocalPort 8080 | Select-Object -ExpandProperty OwningProcess | ForEach-Object { Stop-Process -Id $_ -Force }Linux/Mac:
lsof -ti:8080 | xargs kill -9If you get a "401 Unauthorized" error with "token expired":
- Hard refresh your browser (Ctrl+F5 or Cmd+Shift+R)
- Log out and log back in to get a fresh token
- Tokens expire after 24 hours
If you see CORS errors:
- Ensure the frontend is running on
http://localhost:5173 - Ensure the backend is running on
http://localhost:8080 - The backend has CORS enabled for all origins in development mode
If you see database errors:
- Delete the
backend/data/trading.dbfile - Restart the backend - it will recreate the database
- Log in again
cd frontend
npm run buildOutput will be in frontend/dist/
docker build -t trading-dashboard-backend ./backend
docker build -t trading-dashboard-frontend ./frontendUsername: Any username (auto-creates user on first login)
- Try:
trader1,user123, etc.
| Variable | Default | Description |
|---|---|---|
| JWT_SECRET | dev-secret | Secret key for JWT token signing |
| DB_PATH | ./data/trading.db | Path to SQLite database |
| GIN_MODE | debug | Set to "release" for production |
| Variable | Default | Description |
|---|---|---|
| VITE_API_URL | http://localhost:8080 | Backend API URL |
| VITE_WS_URL | ws://localhost:8080/ws | WebSocket URL |
- Build Docker images
- Use docker-compose or Kubernetes for orchestration
- Set proper environment variables
- Use a reverse proxy (nginx) for frontend serving
- Enable HTTPS
- Use a proper database (PostgreSQL) instead of SQLite
For issues or questions, please check the troubleshooting section above or review the application logs.