The Opinion Trading App is a Node.js and Express.js application designed for real-time trading on sports events. It integrates WebSockets for live updates and uses MongoDB as its database.
✅ User authentication and authorization (JWT-based) ✅ Admin panel to manage sports events ✅ Real-time trade execution and status updates via WebSockets ✅ Fetching live sports data from external APIs ✅ Secure role-based access control
- Backend: Node.js, Express.js
- Database: MongoDB
- Authentication: JWT
- Real-time Communication: WebSockets
- External API: The Odds API
|-- src
| |-- config
| | |-- db.js
| | |-- socket.js
| |-- controllers
| | |-- adminController.js
| | |-- authController.js
| | |-- eventsController.js
| | |-- tradeController.js
| |-- middlewares
| | |-- authAdmin.js
| | |-- authMiddleware.js
| | |-- authorizeRoles.js
| |-- models
| | |-- Event.js
| | |-- Trade.js
| | |-- User.js
| |-- routes
| | |-- adminRoutes.js
| | |-- authRoutes.js
| | |-- eventsRoutes.js
| | |-- tradeRoutes.js
| |-- services
| | |-- apiServices.js
| |-- utils
| | |-- tradeUtils.js
|-- server.js
|-- .env
|-- package.json
|-- README.md
- Node.js (v14 or higher)
- MongoDB (running locally or via cloud service)
- Clone the repository:
git clone https://github.com/your-repo/opinion-trading.git cd opinion-trading - Install dependencies:
npm install
- Create a
.envfile and configure environment variables:MONGO_URI=mongodb://localhost:27017/opinion_trading JWT_SECRET=your_secret_key SPORTS_API_KEY=your_sports_api_key API_URL=https://api.the-odds-api.com/v4/sports/upcoming/odds PORT=5000
- Start the server:
npm start
POST /api/auth/register- Register a new userPOST /api/auth/login- Login userGET /api/auth/profile- Get user profile (requires authentication)
POST /api/events- Create a new event (Admin only)GET /api/events- Fetch all eventsDELETE /api/events/:id- Delete event (Admin only)PUT /api/events/:id- Update event status (Admin only)
POST /api/trades- Create a trade (Authenticated users)GET /api/trades- Get all trades (Admin only)PUT /api/trades/:id- Update trade status (Admin only)
GET /api/admin/fetchlivedata- Fetch live sports dataPUT /api/admin/event/:id/status- Update event status
tradeUpdated- Notifies clients when a trade status changeseventCreated- Notifies clients when a new event is createdeventUpdated- Notifies clients when an event status is updated
🔐 JWT-based authentication for user security 🔐 Role-based access control (Admin/User) 🔐 Environment variables to protect sensitive data
🚀 Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a new feature branch.
- Commit your changes.
- Push to your branch and submit a Pull Request (PR).
📜 MIT License - Free to use and modify!
Made with ❤️ for real-time sports trading!