Skip to content

This is just a trading App in which you change bet on the crypto and buy/sell on crypto

Notifications You must be signed in to change notification settings

SumitKumar777/TradingApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TradingApp πŸ“ˆ

A full-stack trading application built as a monorepo using Turborepo. This platform enables users to place market and limit orders, track positions, manage their wallet balance, and view real-time price data with interactive charts.

πŸ—οΈ Architecture

This project follows a microservices architecture with the following components:

Architecture Diagram

                            TRADING APP - SIMPLIFIED ARCHITECTURE
                            ═══════════════════════════════════════

                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚     BINANCE     β”‚
                                    β”‚   (Price Feed)  β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚  PRICE POLLAR   β”‚
                                    β”‚ (Fetches BTC    β”‚
                                    β”‚  prices)        β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚                REDIS                  β”‚
                         β”‚   (Message Broker - connects all)     β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚                              β”‚                              β”‚
              β–Ό                              β–Ό                              β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚     ENGINE      β”‚           β”‚   WS SERVER     β”‚           β”‚  HTTP BACKEND   β”‚
     β”‚                 β”‚           β”‚                 β”‚           β”‚                 β”‚
     β”‚ β€’ Process ordersβ”‚           β”‚ β€’ Real-time     β”‚           β”‚ β€’ REST API      β”‚
     β”‚ β€’ Calculate P&L β”‚           β”‚   updates to    β”‚           β”‚ β€’ Place orders  β”‚
     β”‚ β€’ Check TP/SL   │◀─────────▢│   browser       β”‚           β”‚ β€’ Auth/Login    β”‚
     β”‚                 β”‚           β”‚                 β”‚           β”‚ β€’ User wallet   β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚                              β”‚                              β”‚
              β”‚                              β”‚                              β”‚
              β–Ό                              β”‚                              β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚   POSTGRESQL    β”‚                     β”‚                    β”‚   TIMESCALEDB   β”‚
     β”‚                 β”‚                     β”‚                    β”‚                 β”‚
     β”‚ β€’ Users         β”‚                     β”‚                    β”‚ β€’ Chart candles β”‚
     β”‚ β€’ Orders        β”‚                     β”‚                    β”‚ β€’ Price history β”‚
     β”‚ β€’ Wallet balanceβ”‚                     β”‚                    β”‚                 β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚   WEB FRONTEND  β”‚
                                    β”‚    (Next.js)    β”‚
                                    β”‚                 β”‚
                                    β”‚ β€’ Trading UI    β”‚
                                    β”‚ β€’ Live charts   β”‚
                                    β”‚ β€’ Place orders  β”‚
                                    β”‚ β€’ View P&L      β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚
                                             β–Ό
                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                    β”‚      USER       β”‚
                                    β”‚    (Browser)    β”‚
                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


                              ═══════════════════════════
                                    HOW IT WORKS
                              ═══════════════════════════

    1. PRICE POLLAR fetches live BTC prices from Binance
    
    2. Prices flow through REDIS to all services
    
    3. USER opens the WEB FRONTEND and sees live prices
    
    4. USER places an order β†’ HTTP BACKEND saves it β†’ ENGINE processes it
    
    5. ENGINE checks Take Profit / Stop Loss on every price tick
    
    6. Updates are pushed to USER via WS SERVER in real-time

Apps

App Description
web Next.js 15 frontend with React 19, featuring interactive trading charts (Lightweight Charts), order management, and a responsive UI built with Radix UI & Tailwind CSS
httpBackend Express.js REST API handling authentication, order placement, wallet management, and user operations
wsServer WebSocket server for real-time price updates and live order notifications
engine Trading engine that processes orders, manages order books, and calculates P&L
pricePollar Service that polls external price feeds and distributes price data via Redis

Packages

Package Description
@repo/db Prisma ORM configuration with PostgreSQL database schema for users and orders
@repo/redisclient Shared Redis client for pub/sub messaging between services
@repo/timescaledb TimescaleDB integration for time-series price data storage
@repo/types Shared TypeScript types and Zod validation schemas
@repo/ui Shared React component library
@repo/eslint-config Shared ESLint configurations
@repo/typescript-config Shared TypeScript configurations

✨ Features

  • Order Management: Place Market and Limit orders with Long/Short positions
  • Wallet System: Deposit funds and track balance
  • Real-time Updates: Live price feeds via WebSocket connections
  • P&L Tracking: Profit and loss calculation for open and closed positions
  • Risk Management: Set Take Profit and Stop Loss levels on orders
  • Interactive Charts: Real-time trading charts powered by Lightweight Charts
  • Authentication: Secure user authentication with JWT tokens

πŸ› οΈ Tech Stack

  • Frontend: Next.js 15, React 19, Tailwind CSS, Radix UI, Zustand, React Hook Form
  • Backend: Express.js, Node.js
  • Real-time: WebSocket (ws)
  • Database: PostgreSQL with Prisma ORM
  • Time-series: TimescaleDB
  • Caching/Messaging: Redis
  • Validation: Zod
  • Build Tool: Turborepo
  • Package Manager: pnpm
  • Language: TypeScript

πŸ“‹ Prerequisites

  • Node.js >= 18
  • pnpm 9.0.0+
  • PostgreSQL
  • Redis
  • TimescaleDB (optional, for price history)

πŸš€ Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/SumitKumar777/TradingApp.git
    cd TradingApp
  2. Install dependencies:

    pnpm install
  3. Set up environment variables:

    # Create .env files in respective apps/packages
    # Required variables:
    DATABASE_URL="postgresql://..."
    REDIS_URL="redis://..."
    JWT_SECRET="your-secret-key"
  4. Generate Prisma client:

    cd packages/db
    pnpm prisma generate
    pnpm prisma db push

Development

Run all apps and packages in development mode:

pnpm dev

Run a specific app:

# Run only the web frontend
pnpm dev --filter=web

# Run only the HTTP backend
pnpm dev --filter=@repo/httpbackend

Build

Build all apps and packages:

pnpm build

Linting

pnpm lint

Type Checking

pnpm check-types

πŸ“ Project Structure

TradingApp/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/              # Next.js frontend
β”‚   β”œβ”€β”€ httpBackend/      # REST API server
β”‚   β”œβ”€β”€ wsServer/         # WebSocket server
β”‚   β”œβ”€β”€ engine/           # Trading engine
β”‚   └── pricePollar/      # Price feed service
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ db/               # Prisma database package
β”‚   β”œβ”€β”€ redisClient/      # Redis client
β”‚   β”œβ”€β”€ timescaledb/      # TimescaleDB integration
β”‚   β”œβ”€β”€ types/            # Shared types & validation
β”‚   β”œβ”€β”€ ui/               # UI component library
β”‚   β”œβ”€β”€ eslint-config/    # ESLint configurations
β”‚   └── typescript-config/# TypeScript configurations
β”œβ”€β”€ turbo.json
β”œβ”€β”€ package.json
└── pnpm-workspace.yaml

πŸ“Š Database Schema

The application uses the following main entities:

  • User: Stores user credentials, email, and wallet balance
  • Orders: Tracks all trading orders with status, P&L, entry/exit prices, and risk parameters

πŸ”§ Configuration

Turborepo

The project uses Turborepo for efficient builds with caching. See turbo.json for task configurations.

Remote Caching

To enable remote caching with Vercel:

turbo login
turbo link

πŸ“„ License

ISC

πŸ‘€ Author

Sumit Kumar


⭐ Star this repo if you find it useful!

About

This is just a trading App in which you change bet on the crypto and buy/sell on crypto

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published