Skip to content

wesleymassine/high-performance-trading

Repository files navigation

🚀 Solana High-Performance Trading Platform

TypeScript Bun Solana License

A production-grade, high-performance trading platform for the Solana ecosystem

Built with modern microservices architecture, event-driven design, and optimized for low-latency trading operations.

🎯 Overview

This platform demonstrates professional-level backend engineering for crypto trading:

  • High Performance: Sub-100ms API responses, real-time WebSocket updates
  • 🏗️ Microservices Architecture: 6 independent services with clear responsibilities
  • 📊 Event-Driven: Redis Streams for reliable inter-service communication
  • 🔒 Production-Ready: Error handling, retries, monitoring, and observability
  • 🎨 Developer Experience: Well-documented APIs, TypeScript strict mode, clean code

🏛️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                        API GATEWAY                          │
│              (REST API + WebSocket Hub)                     │
└──────────────┬──────────────────────────────┬───────────────┘
               │                              │
       ┌───────▼────────┐            ┌────────▼────────┐
       │  PRICE SERVICE │            │  ORDER SERVICE  │
       │  (Market Data) │            │    (Trading)    │
       └───────┬────────┘            └────────┬────────┘
               │                              │
               └──────────┬───────────────────┘
                          │
                ┌─────────▼─────────┐
                │  REDIS STREAMS    │
                │   (Event Bus)     │
                └─────────┬─────────┘
                          │
         ┌────────────────┼────────────────┐
         │                │                │
   ┌─────▼─────┐   ┌─────▼──────┐  ┌─────▼─────┐
   │ PORTFOLIO │   │ ANALYTICS  │  │ WEBHOOK   │
   │ SERVICE   │   │  SERVICE   │  │ SERVICE   │
   └───────────┘   └────────────┘  └───────────┘

🛠️ Tech Stack

Core Technologies

  • Runtime: Bun.js - 3-4x faster than Node.js
  • Language: TypeScript 5.3 (strict mode)
  • Monorepo: Turborepo with pnpm workspaces
  • Blockchain: Solana (via @solana/web3.js + Jupiter SDK)

Infrastructure

  • Database: PostgreSQL 16 (ACID compliance for financial data)
  • Cache/Events: Redis 7 (with Redis Streams)
  • API Framework: Fastify (high-performance HTTP server)
  • WebSocket: Native WebSocket implementation
  • Logging: Pino (structured, high-performance logging)

DevOps

  • Containerization: Docker + Docker Compose
  • CI/CD: GitHub Actions (coming soon)
  • Monitoring: Prometheus + Grafana (optional)

📦 Project Structure

high-performance-trading/
├── apps/
│   ├── api-gateway/          # Main API entry point (REST + WebSocket)
│   ├── price-service/        # Real-time price aggregation
│   ├── order-service/        # Trade execution via Jupiter
│   ├── portfolio-service/    # Portfolio tracking & P&L
│   ├── analytics-service/    # Trading analytics
│   └── webhook-service/      # Event notifications
│
├── packages/
│   ├── shared-types/         # TypeScript types & interfaces
│   ├── solana-client/        # Solana blockchain wrapper
│   ├── redis-client/         # Redis wrapper
│   ├── db-client/            # PostgreSQL client
│   ├── event-bus/            # Redis Streams abstraction
│   ├── logger/               # Structured logging (Pino)
│   └── config/               # Configuration management
│
├── infrastructure/
│   ├── docker/               # Docker configurations
│   └── postgres/             # Database schemas & migrations
│
├── docs/
│   ├── ARCHITECTURE.md       # System architecture details
│   ├── API.md                # API documentation
│   └── SETUP.md              # Setup & deployment guide
│
├── docker-compose.yml        # Local development stack
├── turbo.json                # Turborepo configuration
└── package.json              # Root package.json

🚀 Quick Start

Prerequisites

Installation

# 1. Clone the repository
git clone https://github.com/yourusername/high-performance-trading.git
cd high-performance-trading

# 2. Install dependencies
pnpm install

# 3. Copy environment variables
cp .env.example .env

# 4. Edit .env with your settings
# - Add Helius/QuickNode API keys (optional, can use public RPC)
# - Generate JWT secret: openssl rand -base64 32

# 5. Start infrastructure (Postgres + Redis)
docker-compose up -d

# 6. Wait for services to be healthy (30 seconds)
docker-compose ps

# 7. Start development servers
pnpm dev

Verify Setup

# Check API Gateway health
curl http://localhost:3000/health

# Expected response:
# {"status":"ok","timestamp":1234567890}

# Check logs
docker-compose logs -f

📚 Documentation

🎯 Features

✅ Implemented (MVP)

  • Monorepo structure with Turborepo
  • Docker Compose development environment
  • PostgreSQL schema with migrations
  • Shared TypeScript types
  • Structured logging (Pino)
  • Configuration management
  • API Gateway (in progress)
  • Price Service (in progress)
  • Order Service (in progress)
  • Portfolio Service (planned)
  • Analytics Service (planned)
  • Webhook Service (planned)

🎁 Coming Soon

  • JWT authentication
  • Rate limiting
  • WebSocket real-time updates
  • Jupiter swap integration
  • Multi-wallet support
  • P&L calculation
  • Price alerts
  • API documentation (Swagger)
  • Load tests
  • CI/CD pipeline

🧪 Development

Run All Services

pnpm dev

Run Specific Service

# API Gateway
cd apps/api-gateway && bun run dev

# Price Service
cd apps/price-service && bun run dev

Build for Production

pnpm build

Run Tests

pnpm test

Linting & Formatting

pnpm lint
pnpm format

📊 Performance Targets

  • API Response Time: p95 < 100ms
  • WebSocket Latency: < 50ms
  • Order Execution: < 2 seconds
  • Price Update Frequency: 1-5 seconds
  • Concurrent Users: 100+ (tested with k6)
  • Database Queries: < 50ms

🔐 Environment Variables

See .env.example for all available variables.

Key variables:

# Solana
SOLANA_RPC_URL=https://api.devnet.solana.com
HELIUS_API_KEY=your_key  # Optional, for better performance

# Database
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=trading_platform

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# JWT
JWT_SECRET=your_secret_key

🤝 Contributing

This is a personal project for learning and portfolio purposes, but suggestions are welcome!

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

📝 License

MIT License - see LICENSE file for details

🙏 Acknowledgments

📧 Contact

Wesley Santos


Built with ❤️ for the Solana ecosystem

About

High-performance DEX trading platform on Solana. Real-time price aggregation, automated order execution, and portfolio management with <100ms latency. TypeScript • Bun • Jupiter Protocol • Fastify • PostgreSQL • Redis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors