A real-time stock trading simulation platform with a FastAPI backend and React frontend. TradeSync provides live market data, portfolio tracking, instant order execution, and a built-in fraud detection engine -- built for the modern Indian investor.
- Real-Time Market Data -- WebSocket-powered live prices updating every 2 seconds across 20+ Indian stocks. No page refresh needed.
- Instant Order Execution -- Place BUY and SELL orders with sub-second execution. Automatic balance deduction and portfolio update in a single atomic database transaction.
- Live Portfolio Tracking -- Track P&L per holding, sector-wise allocation with pie charts, and full transaction history.
- Fraud Detection Engine -- Built-in risk checks that flag high-frequency trading, large orders, wash trading, and low balance warnings in real time.
- Watchlist Management -- Add and remove stocks from your personal watchlist to track them at a glance.
- Historical Charts -- 24-hour intraday price charts and 30-day OHLCV data with area chart visualizations.
- Guest and Demo Access -- Try the platform immediately with pre-filled demo credentials or continue as a guest without signing up.
- Admin Dashboard -- Admin panel for user management, stock CRUD, fraud flag monitoring, and platform statistics.
- JWT Authentication -- Secure token-based auth with access and refresh tokens, rate-limited login (5 attempts per 15 minutes), and password validation.
| Technology | Purpose |
|---|---|
| FastAPI | Python async web framework |
| SQLAlchemy | ORM with PostgreSQL support |
| PostgreSQL | Primary database |
| SQLite | Fallback local database |
| Alembic | Database migrations |
| WebSockets | Real-time price broadcasting |
| JWT (python-jose) | Token-based authentication |
| Passlib | Password hashing (bcrypt) |
| Docker | Containerized deployment |
| Uvicorn | ASGI server |
| Technology | Purpose |
|---|---|
| React 18 | UI framework |
| Vite | Build tool and dev server |
| React Router | Client-side routing |
| TailwindCSS | Utility-first CSS framework |
| Recharts | Charting library (area, pie) |
| Axios | HTTP client |
| WebSocket (native) | Real-time price feed |
| Lucide React | Icon library |
tradesync/
app/
api/
routes/
admin.py -- Admin endpoints (users, stocks, fraud flags, dashboard)
auth.py -- Authentication endpoints (register, login, refresh, me)
orders.py -- Order placement, listing, cancellation
portfolio.py -- Portfolio holdings and summary
stocks.py -- Stock listing, detail, and chart data
transactions.py -- Transaction history with pagination
watchlist.py -- Personalized watchlist CRUD
core/
config.py -- Pydantic settings (DATABASE_URL, SECRET_KEY, etc.)
security.py -- JWT creation/decode, password hashing, rate limiter
db/
migrations/ -- Alembic migration scripts
models.py -- SQLAlchemy models (User, Stock, Order, etc.)
session.py -- Database engine, session factory, get_db dependency
services/
fraud_detection.py -- Fraud check pipeline (velocity, large order, wash trade, balance drain)
order_engine.py -- Order validation and atomic execution
price_simulator.py -- Background task generating realistic price movements
websocket/
connection_manager.py -- WebSocket connection tracking and broadcasting
price_feed.py -- WebSocket endpoint for live price streaming
frontend/
src/
components/ -- Reusable UI components (Layout, Sidebar, OrderModal, etc.)
context/ -- AuthContext and PricesContext (React Context API)
hooks/ -- Custom hooks (useAuth, useWebSocket)
pages/ -- Route pages (Landing, Login, Register, Dashboard, etc.)
services/ -- API client, mock data, and service functions
utils/ -- Formatting utilities (currency, date)
main.py -- FastAPI application entry point
seed_db.py -- Database seed script (stocks + demo users)
Dockerfile -- Docker build configuration
docker-compose.yml -- Docker Compose (PostgreSQL + app)
| Model | Purpose |
|---|---|
| User | User accounts with balance, admin flag |
| Stock | Stock master data with current price |
| PortfolioHolding | User's stock holdings with avg buy price |
| Order | Buy/Sell orders with status tracking |
| Transaction | Debit/Credit ledger entries |
| Watchlist | User-stock watchlist relationship |
| FraudFlag | Fraud detection alerts with severity |
| PriceHistory | Historical price snapshots |
| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Create a new user account with email + password |
| POST | /login |
Authenticate and receive JWT tokens |
| POST | /refresh |
Exchange a refresh token for a new token pair |
| GET | /me |
Get current authenticated user profile |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List all active stocks (public) |
| GET | /{symbol} |
Get stock detail with 30-day OHLCV |
| GET | /{symbol}/chart |
Get 24-hour price chart data |
| Method | Endpoint | Description |
|---|---|---|
| POST | /place |
Place a market BUY or SELL order |
| GET | / |
List orders with pagination and filters |
| GET | /{id} |
Get a single order by ID |
| POST | /{id}/cancel |
Cancel a pending order |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Get portfolio holdings with live prices |
| GET | /summary |
Get aggregate portfolio summary stats |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
List transactions with pagination |
| GET | /{id} |
Get a single transaction by ID |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Get current user's watchlist |
| POST | /{symbol} |
Add a stock to watchlist |
| DELETE | /{symbol} |
Remove a stock from wa |