Skip to content

Real-time cryptocurrency trading platform with live market data streaming from Binance, leveraging TimescaleDB for high-performance time-series storage, Redis pub/sub for real-time updates, and WebSocket connections for instant price feeds to a React frontend.

Notifications You must be signed in to change notification settings

abdulbaqui17/CryptoTradingPlatform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ DigitalFortune - Crypto Trading Platform# πŸš€ DigitalFortune - Crypto Trading Platform# πŸš€ DigitalFortune - Real-Time Crypto Trading Platform

TypeScript

React

Docker

PostgreSQL

TypeScriptTypeScript

Real-time cryptocurrency trading platform with microservices architecture

ReactReact

Node.jsNode.js

⚑ Quick Start

DockerDocker

git clone https://github.com/abdulbaqui17/DigitalFortune.git![PostgreSQL](https://img.shields.io/badge/PostgreSQL-316192?logo=postgresql&logoColor=white)![PostgreSQL](https://img.shields.io/badge/PostgreSQL-316192?logo=postgresql&logoColor=white)

cd DigitalFortune

docker-compose up -d --build

Full-stack real-time cryptocurrency trading platform built with React, TypeScript, and microservices****Full-stack cryptocurrency trading platform with real-time features and microservices architecture

Visit http://localhost β†’ New users get $5,000 demo balance!


πŸ› οΈ Built With

Frontend

  • React 19 + TypeScript------

  • Vite (build tool)

  • Tailwind CSS (styling)

  • Framer Motion (animations)

  • Zustand (state management)## ⚑ Quick Start## ⚑ Quick Start

Backend

Databasecd DigitalFortunecd DigitalFortune

  • PostgreSQL (users, orders, positions)

  • Redis (sessions, cache)docker-compose up -d --builddocker-compose up -d --build

DevOps``````

  • Docker + Docker Compose

  • Nginx (reverse proxy)

---Open http://localhost β†’ Sign up β†’ Get $5,000 demo balance β†’ Start trading!Open http://localhost - Every new user gets $5,000 demo balance!

✨ Features

Trading Platform------

  • Real-time candlestick charts (1m to 1D)

  • Market/limit/stop-loss/take-profit orders

  • Up to 100x leverage trading

  • Live P&L tracking## ✨ Features## ✨ Key Features

  • Automated liquidation engine

  • Position management

Security & Auth****Trading### Trading

  • JWT token authentication

  • bcrypt password encryption- Real-time candlestick charts (1m to 1D timeframes)- Real-time candlestick charts with multiple timeframes

  • Protected API routes

  • User-isolated trading accounts- Market, limit, stop-loss, take-profit orders- Market, limit, stop-loss, and take-profit orders

UI/UX- Up to 100x leverage with margin tracking- Up to 100x leverage trading

  • Animated landing page (20+ floating particles)

  • 3D effects with parallax scrolling- Live P&L and position management- Live P&L tracking and position management

  • Responsive mobile design

  • Real-time balance updates- Automated liquidation system- Automated liquidation engine


πŸ—οΈ ArchitectureTech Highlights### Technical


React Client (Nginx)

      ↓- WebSocket real-time data streaming- WebSocket real-time data streaming

HTTP API + WebSocket + Poller

      ↓- Microservices architecture (6 containers)- Microservices architecture (HTTP, WS, Poller services)

PostgreSQL + Redis

```- PostgreSQL + Redis persistence- PostgreSQL + Redis for data persistence



**6 Docker Containers:**- Framer Motion landing page animations- Framer Motion animations on landing page

1. **Client** - React SPA

2. **HTTP Server** - REST API, auth, orders- Responsive design with Tailwind CSS

3. **WebSocket** - Real-time price streaming

4. **Poller** - Market data aggregation

5. **PostgreSQL** - Persistent storage

6. **Redis** - Session cache---



------



## πŸ“ Structure## πŸ› οΈ Tech Stack



```## πŸ› οΈ Tech Stack

DigitalFortune/

β”œβ”€β”€ client/          # React + TypeScript frontend**Frontend:** React 19, TypeScript, Vite, Tailwind CSS, Framer Motion, Zustand  

β”œβ”€β”€ httpserver/      # Express.js API

β”œβ”€β”€ wsserver/        # WebSocket server**Backend:** Node.js, Express.js, TypeScript, WebSocket  **Frontend:** React 19, TypeScript, Vite, Tailwind CSS, Framer Motion, Zustand  

β”œβ”€β”€ poller/          # Market data service

β”œβ”€β”€ db/              # PostgreSQL schemas**Database:** PostgreSQL, Redis  **Backend:** Node.js, Express.js, TypeScript, WebSocket  

└── docker-compose.yml

```**DevOps:** Docker, Docker Compose, Nginx**Database:** PostgreSQL, Redis  



---**DevOps:** Docker, Docker Compose, Nginx



## πŸ”§ Development---



```bash## �️ Architecture

# Start services

docker-compose up -d## πŸ—οΈ Architecture



# View logsMicroservices setup with 6 Docker containers:

docker-compose logs -f

```- **Client** - React SPA with Nginx

# Stop services

docker-compose downβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”- **HTTP Server** - REST API, auth, orders (Express.js)

β”‚ React SPA β”‚ (Nginx :80)- WebSocket Server - Real-time data streaming


β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜- Poller - Market data aggregation

πŸ‘¨β€πŸ’» Author

   β”‚- **PostgreSQL** - User accounts, orders, positions

Abdul Baqui

GitHub: @abdulbaqui17 β”Œβ”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”- Redis - Session cache

--- β”‚ β”‚ β”‚

β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”## οΏ½ Development

Built with React, TypeScript, Docker & PostgreSQLβ”‚ HTTP API β”‚ β”‚ WebSocketβ”‚ β”‚ Poller β”‚

⭐ Star this repo if you find it useful!β”‚ :3001 β”‚ β”‚ :3002 β”‚ β”‚ (Background)β”‚```bash

β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜# Start dev environment
 β”‚             β”‚              β”‚docker-compose up -d

 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

           β”‚# View logs

    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”docker-compose logs -f httpserver

    β”‚             β”‚

β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”# Stop services

β”‚PostgreSQLβ”‚ β”‚ Redis β”‚docker-compose down

β”‚ :5432 β”‚ β”‚ :6379 β”‚```

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜




**Services:**## πŸ“ Project Structure

- **Client** - React SPA with landing page + trading dashboard

- **HTTP Server** - REST API, auth, order management, risk engine```

- **WebSocket Server** - Real-time price updates and trade eventsDigitalFortune/

- **Poller** - Market data aggregation and candle generationβ”œβ”€β”€ client/                    # React Frontend

- **PostgreSQL** - User accounts, orders, positionsβ”‚   β”œβ”€β”€ src/

- **Redis** - Session storage and cachingβ”‚   β”‚   β”œβ”€β”€ components/       # Reusable components

β”‚   β”‚   β”‚   β”œβ”€β”€ landing/      # Landing page components

---β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LandingNavbar.tsx

β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ HeroSection.tsx (with animations)

## πŸ“ Project Structureβ”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeaturesSection.tsx

β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardPreview.tsx (3D effects)

```β”‚   β”‚   β”‚   β”‚   └── LandingFooter.tsx

DigitalFortune/β”‚   β”‚   β”‚   β”œβ”€β”€ chart/        # Trading chart components

β”œβ”€β”€ client/          # React frontend (Vite + TypeScript)β”‚   β”‚   β”‚   β”œβ”€β”€ orders/       # Order management UI

β”œβ”€β”€ httpserver/      # Express.js API serverβ”‚   β”‚   β”‚   └── positions/    # Position tracking UI

β”œβ”€β”€ wsserver/        # WebSocket serverβ”‚   β”‚   β”œβ”€β”€ pages/

β”œβ”€β”€ poller/          # Market data pollerβ”‚   β”‚   β”‚   β”œβ”€β”€ Landing.tsx   # Landing page

β”œβ”€β”€ db/              # PostgreSQL init scriptsβ”‚   β”‚   β”‚   └── Dashboard.tsx # Trading dashboard

└── docker-compose.ymlβ”‚   β”‚   β”œβ”€β”€ hooks/            # Custom React hooks

```β”‚   β”‚   β”œβ”€β”€ lib/              # Utilities & helpers

β”‚   β”‚   β”œβ”€β”€ store/            # Zustand state management

---β”‚   β”‚   └── types/            # TypeScript definitions

β”‚   β”œβ”€β”€ Dockerfile

## πŸ”§ Developmentβ”‚   β”œβ”€β”€ package.json

β”‚   └── vite.config.ts

```bashβ”‚

# Start all servicesβ”œβ”€β”€ httpserver/               # HTTP API Server

docker-compose up -dβ”‚   β”œβ”€β”€ src/

β”‚   β”‚   β”œβ”€β”€ index.ts          # Main server & routes

# View logsβ”‚   β”‚   β”œβ”€β”€ riskEngine.ts     # Risk management

docker-compose logs -f httpserverβ”‚   β”‚   β”œβ”€β”€ sl_tp_watcher.ts  # Stop-loss/Take-profit watcher

β”‚   β”‚   β”œβ”€β”€ engine/

# Rebuild specific serviceβ”‚   β”‚   β”‚   β”œβ”€β”€ margin.ts     # Margin calculations

docker-compose up -d --build clientβ”‚   β”‚   β”‚   └── simpleMargin.ts

β”‚   β”‚   β”œβ”€β”€ lib/

# Stop everythingβ”‚   β”‚   β”‚   β”œβ”€β”€ liquidation.ts

docker-compose downβ”‚   β”‚   β”‚   β”œβ”€β”€ money.ts

```β”‚   β”‚   β”‚   └── risk.ts

β”‚   β”‚   └── risk/

**Access Points:**β”‚   β”‚       β”œβ”€β”€ liquidation.ts

- Frontend: http://localhostβ”‚   β”‚       β”œβ”€β”€ liquidator.ts

- API: http://localhost:3001β”‚   β”‚       └── snapshot.ts

- WebSocket: ws://localhost:3002β”‚   β”œβ”€β”€ Dockerfile

β”‚   └── package.json

---β”‚

β”œβ”€β”€ wsserver/                 # WebSocket Server

## πŸ“¦ What's Insideβ”‚   β”œβ”€β”€ src/

β”‚   β”‚   β”œβ”€β”€ index.ts          # WebSocket handler

**Landing Page**β”‚   β”‚   └── alerts.ts         # Alert system

- Eye-catching hero with 20+ floating particlesβ”‚   β”œβ”€β”€ Dockerfile

- Feature cards with hover animationsβ”‚   └── package.json

- 3D dashboard preview with parallax scrollingβ”‚

- Mobile-responsive designβ”œβ”€β”€ poller/                   # Market Data Poller

β”‚   β”œβ”€β”€ src/

**Trading Dashboard**β”‚   β”‚   └── index.ts          # Price polling & candles

- Left sidebar: Instrument listβ”‚   β”œβ”€β”€ Dockerfile

- Center: Real-time charts + positions panelβ”‚   └── package.json

- Right sidebar: Order panel with leverage sliderβ”‚

- Live balance and margin displayβ”œβ”€β”€ db/

β”‚   └── init.sql              # Database schema

**Backend**β”‚

- JWT auth with 7-day token expirationβ”œβ”€β”€ docker-compose.yml        # Service orchestration

- User-specific order isolation└── README.md                 # This file

- Real-time margin monitoring```

- Automated stop-loss/take-profit execution

- Liquidation engine triggers at 0% margin---



---## πŸ“‘ API Documentation



## πŸš€ Deployment### Authentication Endpoints



### Docker (Recommended)#### `POST /api/v1/signup`

```bashRegister a new user (receives $5,000 demo balance).

# On your server

git clone https://github.com/abdulbaqui17/DigitalFortune.git**Request:**

cd DigitalFortune```json

docker-compose up -d --build{

```  "email": "user@example.com",

  "password": "securePassword123",

### Manual  "username": "trader123"

```bash}

# Install dependencies```

cd client && npm install && cd ..

cd httpserver && npm install && cd ..**Response:**

cd wsserver && npm install && cd ..```json

cd poller && npm install && cd ..{

  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",

# Start services  "user": {

docker-compose up -d postgres redis    "id": 1,

cd httpserver && npm start &    "email": "user@example.com",

cd wsserver && npm start &    "username": "trader123"

cd poller && npm start &  }

cd client && npm run build && npx serve dist}

---#### POST /api/v1/signin

Login existing user.

🀝 Contributing

Request:

  1. Fork the repo```json

  2. Create feature branch (git checkout -b feature/amazing){

  3. Commit changes (git commit -m 'Add amazing feature') "email": "user@example.com",

  4. Push to branch (git push origin feature/amazing) "password": "securePassword123"

  5. Open Pull Request}


---

---

## πŸ“„ License

### Account Endpoints

MIT License - feel free to use for your projects!

#### `GET /api/v1/account`

---Get account balance and margin info.



## πŸ‘¨β€πŸ’» Author**Headers:** `Authorization: Bearer {token}`



**Abdul Baqui**  **Response:**

GitHub: [@abdulbaqui17](https://github.com/abdulbaqui17)```json

{

---  "balance": 5000.00,

  "equity": 5234.50,

<div align="center">  "free": 4500.00,

  "used": 734.50,

### ⭐ Star this repo if you find it helpful!  "upnl": 234.50,

  "level": 712.5,

Built with ❀️ using React, TypeScript, and Docker  "maintenance": 367.25

}

</div>```


---

### Trading Endpoints

#### `POST /api/v1/orders`
Place a new order.

**Request:**
```json
{
  "symbol": "BTCUSDT",
  "side": "buy",
  "type": "market",
  "quantity": 0.1,
  "leverage": 10,
  "stopLoss": 45000,
  "takeProfit": 55000
}

GET /api/v1/orders

Get open orders.

GET /api/v1/positions

Get open positions with P&L.

POST /api/v1/positions/:id/close

Close a position.


Market Data Endpoints

GET /api/v1/candles/:symbol

Get historical candles.

Query Params:

  • interval: 1m, 5m, 15m, 1h, 4h, 1d
  • limit: Number of candles (default: 100)

WebSocket Events

Client β†’ Server:

// Subscribe to market data
ws.send(JSON.stringify({
  type: 'subscribe',
  symbol: 'BTCUSDT'
}));

Server β†’ Client:

// Price update
{
  type: 'price',
  symbol: 'BTCUSDT',
  price: 43521.50,
  timestamp: 1699267200000
}

// Trade execution
{
  type: 'trade',
  orderId: 123,
  status: 'filled',
  price: 43521.50
}

// Position update
{
  type: 'position',
  positionId: 456,
  upnl: 234.50,
  roe: 4.69
}

πŸ’» Development

Available Scripts

Client

npm run dev          # Start dev server (Vite)
npm run build        # Build for production
npm run preview      # Preview production build
npm run lint         # Run ESLint

Backend Services

npm run dev          # Start with nodemon (auto-reload)
npm run build        # Compile TypeScript
npm start            # Start production server

Environment Variables

Create .env files in each service directory:

httpserver/.env:

DATABASE_URL=postgresql://postgres:postgres@postgres:5432/trading
JWT_SECRET=your-super-secret-jwt-key-change-in-production
PORT=3001
REDIS_URL=redis://redis:6379

wsserver/.env:

WS_PORT=3002
REDIS_URL=redis://redis:6379

🚒 Deployment

Production Deployment

Option 1: VPS/Cloud Server

# On your server
git clone https://github.com/abdulbaqui17/DigitalFortune.git
cd DigitalFortune

# Configure environment variables
nano .env

# Build and start services
docker-compose -f docker-compose.yml up -d --build

# Setup Nginx reverse proxy (optional)
sudo nano /etc/nginx/sites-available/trading

Sample Nginx config:

server {
    listen 80;
    server_name your-domain.com;

    location / {
        proxy_pass http://localhost;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /ws {
        proxy_pass http://localhost:3002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
}

Option 2: Docker Swarm

docker swarm init
docker stack deploy -c docker-compose.yml trading

Option 3: Kubernetes

kubectl apply -f k8s/

πŸ“Έ Screenshots

Landing Page

  • Eye-catching hero section with 20 floating particles
  • Animated gradients and pulsing orbs
  • 3D dashboard preview with parallax scrolling
  • Feature cards with hover effects

Trading Dashboard

  • Real-time candlestick charts
  • Order panel with leverage slider
  • Position tracking with live P&L
  • Balance display with margin info

πŸŽ“ What You'll Learn

By exploring this project, you'll understand:

  1. Full-Stack TypeScript Development

    • Type-safe frontend and backend
    • Shared types between services
    • Advanced TypeScript patterns
  2. Real-Time Systems

    • WebSocket implementation
    • Event-driven architecture
    • Live data streaming
  3. Microservices Architecture

    • Service separation
    • Inter-service communication
    • Docker orchestration
  4. Advanced Frontend

    • Complex state management
    • Real-time UI updates
    • Performance optimization
    • Advanced animations
  5. Trading Systems

    • Order matching engines
    • Margin calculations
    • Risk management
    • Liquidation logic
  6. DevOps Practices

    • Containerization
    • Multi-stage Docker builds
    • Service orchestration
    • Production deployment

🀝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/AmazingFeature
  3. Commit your changes
    git commit -m 'Add some AmazingFeature'
  4. Push to the branch
    git push origin feature/AmazingFeature
  5. Open a Pull Request

Contribution Ideas

  • Add more cryptocurrency pairs
  • Implement order book visualization
  • Add trading indicators (RSI, MACD, etc.)
  • Implement social trading features
  • Add mobile app (React Native)
  • Integrate real exchange APIs
  • Add backtesting functionality
  • Implement trading bots

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Abdul Baqui


πŸ™ Acknowledgments

  • TradingView for Lightweight Charts
  • Framer Motion for animation library
  • Tailwind Labs for Tailwind CSS
  • Vercel for Zustand state management
  • The open-source community

πŸ“Š Project Stats

  • Lines of Code: ~15,000+
  • Components: 40+
  • API Endpoints: 20+
  • WebSocket Events: 10+
  • Database Tables: 8
  • Docker Services: 6
  • Technologies Used: 15+

🎯 Future Roadmap

  • Phase 1: Real exchange integration (Binance API)
  • Phase 2: Mobile app development
  • Phase 3: Social trading features
  • Phase 4: Algorithmic trading bots
  • Phase 5: Copy trading functionality
  • Phase 6: NFT marketplace integration

⭐ Star this repository if you find it helpful!

Built with ❀️ by Abdul Baqui

About

Real-time cryptocurrency trading platform with live market data streaming from Binance, leveraging TimescaleDB for high-performance time-series storage, Redis pub/sub for real-time updates, and WebSocket connections for instant price feeds to a React frontend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages