Skip to content

anand9125/exness

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Exness Trading Platform

Demo Video : #1 (comment)

A high-performance cryptocurrency trading platform with real-time price feeds, WebSocket streaming, and multi-timeframe candlestick data aggregation.

πŸ—οΈ Architecture Overview

App Screenshot

πŸ”§ Components

1. Price Poller

  • Fetches real-time cryptocurrency prices from Binance API
  • Continuously polls price data at configured intervals
  • Publishes updates to WebSocket service for real-time distribution

2. WebSocket Service (WS)

  • Pub/Sub architecture for real-time price broadcasting
  • Subscribes to price updates from the Price Poller
  • Publishes live data to connected frontend clients
  • Maintains active WebSocket connections for low-latency updates

3. Batch Uploader

  • Processes incoming price data in batches
  • Aggregates data into multiple timeframe buckets
  • Efficiently writes to time-series databases
  • Handles data normalization and validation

4. Database Layer

Multi-instance time-series database architecture:

  • db_1m: 1-minute candlestick data
  • db_2m: 2-minute candlestick data
  • db_3m: 3-minute candlestick data
  • *db_n: Additional configurable timeframes

5. Backend (BE)

  • RESTful API endpoints for historical data queries
  • WebSocket connection management
  • Authentication and authorization
  • Rate limiting and request validation

6. Frontend (FE)

  • Real-time price charts and trading interface
  • WebSocket client for live price feeds
  • Historical candlestick data visualization
  • Asset selection and timeframe controls

πŸš€ Features

  • βœ… Real-time price streaming via WebSocket
  • βœ… Multi-asset support
  • βœ… Multiple timeframe candlestick aggregation (1m, 2m, 3m, etc.)
  • βœ… Historical OHLCV data API
  • βœ… Efficient batch processing and storage
  • βœ… Scalable pub/sub architecture
  • βœ… Low-latency price updates from Binance

πŸ“‘ API Endpoints

Get Candlestick Data

GET /candles?asset={symbol}&timeframe={interval}&limit={count}

Parameters:

  • asset (required): Trading pair symbol (e.g., SOL, BTC, ETH)
  • timeframe (optional): Candle interval - 1m, 2m, 3m, etc. (default: 1m)
  • limit (optional): Number of candles to return (default: 100, max: 1000)

Example Request:

curl "https://api.exness.com/candles?asset=sol&timeframe=1m&limit=500"

Response:

{
  "asset": "SOL",
  "timeframe": "1m",
  "candles": [
    {
      "timestamp": 1704067200000,
      "open": 101.23,
      "high": 101.89,
      "low": 101.15,
      "close": 101.76,
      "volume": 15234.56
    }
  ]
}

WebSocket Connection

Endpoint:

wss://api.exness.com/ws

Subscribe to Price Updates:

{
  "action": "subscribe",
  "assets": ["SOL", "BTC", "ETH"]
}

Incoming Price Updates:

{
  "type": "price_update",
  "asset": "SOL",
  "price": 101.76,
  "timestamp": 1704067200000,
  "volume": 1234.56
}

πŸ› οΈ Technology Stack

  • Backend: Node.js / Rust (specify your choice)
  • Database: TimescaleDB / InfluxDB (specify your choice)
  • WebSocket: Socket.io / ws library
  • Message Queue: Redis / RabbitMQ (specify if used)
  • Frontend: React / Next.js (specify your choice)
  • External API: Binance REST & WebSocket APIs

πŸ“¦ Installation

Prerequisites

  • Node.js 18+ or Rust 1.70+
  • PostgreSQL 14+ (with TimescaleDB extension) or InfluxDB 2.0+
  • Redis 7+ (optional, for caching)

Setup

  1. Clone the repository
git clone https://github.com/yourusername/exness.git
cd exness
  1. Install dependencies
# Backend
cd backend
npm install  # or cargo build

# Frontend
cd ../frontend
npm install
  1. Configure environment variables
cp .env.example .env

Edit .env:

# Database
DATABASE_URL=postgresql://user:password@localhost:5432/exness
TIMESCALE_ENABLED=true

# Binance API
BINANCE_API_URL=https://api.binance.com
BINANCE_WS_URL=wss://stream.binance.com:9443

# Redis (optional)
REDIS_URL=redis://localhost:6379

# Server
PORT=3000
WS_PORT=3001

# Assets to track
TRACKED_ASSETS=BTC,ETH,SOL,AVAX,MATIC
  1. Initialize database
# Run migrations
npm run migrate

# Or with TimescaleDB
psql -U postgres -d exness -f migrations/init_timescale.sql
  1. Start services

Development:

# Terminal 1: Start price poller
npm run poller

# Terminal 2: Start WebSocket service
npm run ws-service

# Terminal 3: Start backend API
npm run backend

# Terminal 4: Start frontend
cd frontend && npm run dev

Production:

# Using Docker Compose (see Docker section below)
docker compose up -d

# Or with PM2
pm2 start ecosystem.config.js

Docker (local & EC2)

All backends and the web app are containerized. Pub/sub uses Redis (no database required).

Prerequisites: Docker and Docker Compose.

Build and run locally:

# From repo root
docker compose up --build

# Or run in background
docker compose up -d --build

Services:

  • Redis – localhost:6379 (pub/sub)
  • pooler – Binance β†’ Redis (no exposed port)
  • server – REST API – http://localhost:4000
  • ws – WebSocket – ws://localhost:8080
  • web – Next.js – http://localhost:3000

Env for production (e.g. EC2): Set in docker-compose.yml or a .env file:

  • REDIS_URL – Redis connection (e.g. redis://redis:6379 in Docker)
  • NEXT_PUBLIC_BACKEND_URL / NEXT_PUBLIC_WS_URL – API and WebSocket URLs the browser will use (e.g. your EC2 hostname)

πŸ”„ Data Flow

  1. Price Ingestion

    • Price Poller connects to Binance WebSocket
    • Receives real-time tick data for configured assets
    • Validates and normalizes price data
  2. Real-time Distribution

    • Publishes to WebSocket service via pub/sub
    • WS service broadcasts to all subscribed clients
    • Frontend updates charts in real-time
  3. Data Aggregation

    • Batch Uploader collects ticks in memory buffers
    • Aggregates into OHLCV candles at multiple intervals
    • Flushes batches to respective database instances
  4. Historical Queries

    • Frontend requests historical data via REST API
    • Backend queries appropriate timeframe database
    • Returns paginated candlestick data

πŸ“Š Database Schema

Candlestick Tables (per timeframe)

CREATE TABLE candles_1m (
    timestamp TIMESTAMPTZ NOT NULL,
    asset VARCHAR(20) NOT NULL,
    open DECIMAL(20, 8) NOT NULL,
    high DECIMAL(20, 8) NOT NULL,
    low DECIMAL(20, 8) NOT NULL,
    close DECIMAL(20, 8) NOT NULL,
    volume DECIMAL(20, 8) NOT NULL,
    PRIMARY KEY (timestamp, asset)
);

-- TimescaleDB hypertable conversion
SELECT create_hypertable('candles_1m', 'timestamp');

-- Create indexes
CREATE INDEX idx_candles_1m_asset ON candles_1m (asset, timestamp DESC);

βš™οΈ Configuration

Timeframe Configuration

Edit config/timeframes.json:

{
  "timeframes": [
    { "interval": "1m", "seconds": 60, "retention_days": 7 },
    { "interval": "2m", "seconds": 120, "retention_days": 14 },
    { "interval": "3m", "seconds": 180, "retention_days": 30 },
    { "interval": "5m", "seconds": 300, "retention_days": 60 },
    { "interval": "15m", "seconds": 900, "retention_days": 90 },
    { "interval": "1h", "seconds": 3600, "retention_days": 365 }
  ]
}

Asset Configuration

Edit config/assets.json:

{
  "assets": [
    { "symbol": "SOL", "binance_pair": "SOLUSDT", "precision": 8 },
    { "symbol": "BTC", "binance_pair": "BTCUSDT", "precision": 8 },
    { "symbol": "ETH", "binance_pair": "ETHUSDT", "precision": 8 }
  ]
}

πŸ§ͺ Testing

# Run unit tests
npm test

# Run integration tests
npm run test:integration

# Run load tests
npm run test:load

πŸ“ˆ Performance Optimization

  • Database Indexing: Compound indexes on (asset, timestamp)
  • TimescaleDB Compression: Automatic compression for older data
  • Connection Pooling: Reuse database connections
  • Batch Processing: Aggregate writes to reduce database load
  • Redis Caching: Cache frequently accessed candlestick data
  • WebSocket Throttling: Rate-limit price updates to prevent client overload

πŸ”’ Security

  • Rate limiting on API endpoints
  • WebSocket connection authentication
  • Input validation and sanitization
  • SQL injection prevention with parameterized queries
  • CORS configuration for frontend access

πŸ“ License

MIT License - see LICENSE file for details

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.

πŸ“§ Contact

For questions or support, reach out to [your-email@example.com]


Built with ❀️ for high-frequency trading

About

A broker-style CFD execution engine that simulates order handling and trade execution.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors