A modern, full-stack trading application that integrates with Kite Connect API. Features a React frontend with a professional trading interface and a secure Express.js backend.
- 🔐 Secure Authentication: OAuth-like flow with Kite Connect
- 📊 Trading Interface: Place BUY/SELL orders with real-time feedback
- 💼 Portfolio Management: View holdings, positions, and order history
- 🎨 Modern UI: Responsive design with Tailwind-inspired styling
- 🔒 Security: Environment-based credential management
- ⚡ Fast: Built with Bun runtime and Vite for optimal performance
├── backend/ # Express.js API server
│ ├── server.ts # Main server file
│ └── routes/ # API route handlers
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── components/ # React components
│ │ └── App.tsx # Main app component
│ └── package.json # Frontend dependencies
├── trade.ts # Kite Connect integration
└── package.json # Backend dependencies
- Bun installed on your system
- Kite Connect API credentials (API Key & Secret)
- Clone and install dependencies:
bun install
cd frontend && bun install- Set up environment variables:
cp .env.example .env- Configure your Kite Connect credentials in
.env:
KITE_API_KEY=your_api_key_here
KITE_API_SECRET=your_api_secret_here
PORT=3001
NODE_ENV=development
FRONTEND_URL=http://localhost:3000Option 1: Run both frontend and backend together:
bun run devOption 2: Run separately:
Backend (Terminal 1):
bun run serverFrontend (Terminal 2):
bun run clientThe application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- Open the application in your browser
- Enter your Kite Connect API Key and Secret
- Click "Get Login URL" to open Kite Connect login
- Complete authentication on Kite Connect
- Copy the request token from the redirect URL
- Paste the token and complete authentication
- Once authenticated, you'll see the trading interface
- Enter the trading symbol (e.g., RELIANCE, TCS)
- Specify the quantity
- Choose BUY or SELL
- Click "Place Order" to execute the trade
- View your current holdings
- Check open positions with P&L
- Review recent orders
- Refresh data anytime
- Backend: Express.js server with TypeScript
- Frontend: React with TypeScript and Vite
- API: RESTful endpoints for all trading operations
- Security: Environment variables and input validation
backend/server.ts- Main Express serverbackend/routes/auth.ts- Authentication endpointsbackend/routes/trade.ts- Trading operationsfrontend/src/App.tsx- Main React applicationtrade.ts- Kite Connect integration service
Authentication:
POST /api/auth/login-url- Get Kite Connect login URLPOST /api/auth/generate-token- Exchange request token for access tokenGET /api/auth/profile/:sessionId- Get user profilePOST /api/auth/logout/:sessionId- Logout and clear session
Trading:
POST /api/trade/place-order- Place a trading orderGET /api/trade/orders/:sessionId- Get order historyGET /api/trade/positions/:sessionId- Get current positionsGET /api/trade/holdings/:sessionId- Get portfolio holdings
- Environment variable management for credentials
- Input validation with Zod schemas
- Session-based authentication
- CORS configuration
- Error handling without information leakage
Create a .env file with the following variables:
# Kite Connect API Credentials
KITE_API_KEY=your_api_key_here
KITE_API_SECRET=your_api_secret_here
# Server Configuration
PORT=3001
NODE_ENV=development
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:3000- Never commit your
.envfile - it contains sensitive credentials - Use the
.env.exampleas a template for required variables - Kite Connect credentials are required for the application to work
- Session management is currently in-memory (use Redis for production)
-
"KITE_API_KEY and KITE_API_SECRET must be set"
- Ensure your
.envfile exists and contains the required variables
- Ensure your
-
"Session not found"
- Re-authenticate with Kite Connect
- Check if your session has expired
-
CORS errors
- Ensure the backend is running on port 3001
- Check FRONTEND_URL in your
.envfile
-
Order placement fails
- Verify you have sufficient funds
- Check if the market is open
- Ensure the trading symbol is correct
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is for educational purposes. Please ensure compliance with Kite Connect's terms of service and applicable regulations.
Built with ❤️ using Bun, React, and TypeScript