Skip to content

Crypto Trading Terminal | React.js + Typescript + Redux Toolkit + Redux Saga + Tailwind CSS + Vite +Node.js

Notifications You must be signed in to change notification settings

gmaxsoft/CryptoTradingTerminal

Repository files navigation

Crypto Trading Terminal

Demo Preview

High-performance real-time cryptocurrency trading dashboard integrated with Binance Public API. Built with React, TypeScript, Redux Toolkit, and Redux Saga for professional-grade state management and WebSocket streaming.

πŸš€ Features

Real-time Market Data

  • Live Price Ticker: Real-time price updates for BTC/USDT and other trading pairs
  • 24h Statistics: Price change, volume, high/low indicators with color-coded visualization
  • Symbol Switcher: Quick switching between popular trading pairs (BTC, ETH, BNB, SOL, ADA, XRP, DOGE, DOT)

Order Book

  • Depth Stream (L2): Real-time order book with 20 price levels
  • Price Aggregation: Intelligent order aggregation with cumulative totals
  • Visual Bars: Depth visualization showing bid/ask distribution
  • Spread Calculation: Real-time bid/ask spread with percentage display

Architecture Highlights

  • WebSocket Management: Automatic connection lifecycle with reconnection logic
  • Performance Optimized: Throttled updates (100ms) to prevent Redux store overload
  • Memory Safe: Proper cleanup of WebSocket connections and listeners
  • Type Safe: Strict TypeScript with no any types
  • Feature-based Structure: Clean, maintainable code organization

πŸ› οΈ Technologies

  • React 18 - Modern UI framework with hooks
  • TypeScript 5.3 - Static typing for type safety
  • Redux Toolkit 2.0 - Efficient state management
  • Redux Saga 1.3 - Complex async flows and WebSocket handling
  • Tailwind CSS 3.4 - Utility-first CSS framework
  • Vite 5.1 - Fast build tool and dev server
  • Axios 1.13 - HTTP client for REST API calls
  • Binance Public API - Market data source (REST + WebSocket)

πŸ“‹ Prerequisites

  • Node.js 20.x or 22.x (LTS recommended)
  • npm or yarn package manager

πŸ”§ Installation

# Clone the repository
git clone <repository-url>
cd CryptoTradingTerminal

# Install dependencies
npm install

πŸš€ Running

# Development mode (with hot reload)
npm run dev

# Production build
npm run build

# Preview production build locally
npm run preview

The application will start on http://localhost:5173 (or the next available port).

πŸ§ͺ Testing

The project includes comprehensive test coverage using Vitest and React Testing Library.

Running Tests

# Run tests in watch mode
npm test

# Run tests with UI
npm test:ui

# Run tests once
npm test -- --run

Test Coverage

The test suite covers:

  • Components: App, MarketTicker, SymbolSwitcher, OrderBook
  • Redux Slices: marketSlice, orderbookSlice (state management)
  • Selectors: marketSelectors, orderbookSelectors (memoized selectors)
  • Utilities: formatters (price, volume, percent formatting), orderbook utils (aggregation, merging)

Test Structure

Tests are co-located with their source files using the .test.ts and .test.tsx naming convention:

src/
β”œβ”€β”€ App.test.tsx
β”œβ”€β”€ common/utils/
β”‚   └── formatters.test.ts
β”œβ”€β”€ features/
β”‚   β”œβ”€β”€ market/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ MarketTicker.test.tsx
β”‚   β”‚   β”‚   └── SymbolSwitcher.test.tsx
β”‚   β”‚   └── store/
β”‚   β”‚       β”œβ”€β”€ marketSlice.test.ts
β”‚   β”‚       └── marketSelectors.test.ts
β”‚   └── orderbook/
β”‚       β”œβ”€β”€ components/
β”‚       β”‚   └── OrderBook.test.tsx
β”‚       β”œβ”€β”€ store/
β”‚       β”‚   β”œβ”€β”€ orderbookSlice.test.ts
β”‚       β”‚   └── orderbookSelectors.test.ts
β”‚       └── utils.test.ts
└── test/
    β”œβ”€β”€ setup.ts          # Test configuration
    └── testUtils.tsx     # Testing utilities (renderWithProviders)

Testing Tools

  • Vitest 4.0 - Fast unit test framework
  • React Testing Library - Component testing utilities
  • @testing-library/jest-dom - Custom Jest matchers for DOM
  • jsdom - DOM environment for testing

Test Configuration

Tests are configured in vitest.config.ts with:

  • React plugin support
  • jsdom environment for DOM testing
  • Path aliases (@/ for src/)
  • Global test setup via src/test/setup.ts

πŸ“ Project Structure

src/
β”œβ”€β”€ api/                          # Binance API integration
β”‚   β”œβ”€β”€ binanceRest.ts           # REST API client (Axios)
β”‚   └── binanceSockets.ts        # WebSocket client (eventChannel)
β”œβ”€β”€ assets/                       # Global styles, images
β”‚   └── index.css                # Tailwind CSS imports
β”œβ”€β”€ common/                       # Shared utilities
β”‚   β”œβ”€β”€ constants/               # API endpoints, configuration
β”‚   β”‚   └── binance.ts
β”‚   β”œβ”€β”€ types/                   # Global TypeScript interfaces
β”‚   β”‚   └── binance.ts
β”‚   └── utils/                   # Formatters and helpers
β”‚       └── formatters.ts
β”œβ”€β”€ features/                    # Feature modules
β”‚   β”œβ”€β”€ market/                  # Market ticker feature
β”‚   β”‚   β”œβ”€β”€ components/         # MarketTicker, SymbolSwitcher
β”‚   β”‚   β”œβ”€β”€ store/
β”‚   β”‚   β”‚   β”œβ”€β”€ marketSlice.ts  # Redux slice
β”‚   β”‚   β”‚   β”œβ”€β”€ marketSaga.ts   # WebSocket saga with throttling
β”‚   β”‚   β”‚   └── marketSelectors.ts # Memoized selectors
β”‚   β”‚   └── index.ts            # Public API
β”‚   └── orderbook/               # Order book feature
β”‚       β”œβ”€β”€ components/         # OrderBook component
β”‚       β”œβ”€β”€ store/
β”‚       β”‚   β”œβ”€β”€ orderbookSlice.ts
β”‚       β”‚   β”œβ”€β”€ orderbookSaga.ts # Depth stream saga
β”‚       β”‚   └── orderbookSelectors.ts
β”‚       β”œβ”€β”€ types.ts            # Order book types
β”‚       └── utils.ts             # Aggregation logic
β”œβ”€β”€ store/                        # Redux store configuration
β”‚   β”œβ”€β”€ rootReducer.ts           # Combined reducers
β”‚   β”œβ”€β”€ rootSaga.ts              # Root saga (all feature sagas)
β”‚   β”œβ”€β”€ hooks.ts                 # Typed Redux hooks
β”‚   └── index.ts                 # Store setup
β”œβ”€β”€ App.tsx                       # Main application component
└── main.tsx                      # Application entry point

πŸ—οΈ Architecture

State Management

  • Redux Toolkit: Modern Redux with simplified API
  • Redux Saga: Side effects management using generators
  • Reselect: Memoized selectors for performance optimization

WebSocket Pattern

  • eventChannel: Redux Saga pattern for WebSocket streams
  • Automatic Cleanup: Proper cancellation on component unmount
  • Reconnection Logic: Built-in error handling and reconnection

Performance Optimizations

  • Throttling: 100ms throttling for ticker and orderbook updates
  • Memoized Selectors: Prevents unnecessary re-renders
  • Code Splitting: Feature-based code organization

πŸ”„ CI/CD

GitHub Actions workflows are configured for:

  • CI: Automated testing on Node.js 20.x and 22.x
  • Type Checking: TypeScript compilation verification
  • Build Verification: Production build testing
  • Deploy: Automated deployment on main branch

See .github/workflows/ for details.

πŸ“ Key Implementation Details

WebSocket Lifecycle

  1. Connection: Automatic WebSocket connection on symbol change
  2. Subscription: Subscribe to ticker/depth streams
  3. Updates: Throttled updates to Redux store
  4. Cleanup: Automatic cancellation on symbol change or unmount

Order Book Flow

  1. Snapshot: Load initial order book from REST API
  2. Stream: Subscribe to depth stream updates
  3. Merge: Merge incremental updates with snapshot
  4. Aggregate: Calculate cumulative totals for visualization

Symbol Switching

  • Cancels existing WebSocket connections
  • Resets state for old symbol
  • Initializes new streams for selected symbol
  • Synchronizes market and orderbook data

🎨 UI Features

  • Dark Theme: Professional dark UI optimized for trading
  • Responsive Design: Works on desktop and tablet
  • Real-time Updates: Live price and order book updates
  • Color Coding: Green/red indicators for price changes
  • Loading States: Skeleton loaders during data fetch

πŸ“„ License

MIT

πŸ‘€ Author

Maxsoft


Note: This application uses Binance Public API. No API keys are required for market data access. For trading functionality, API keys would be needed (not implemented in this version).

About

Crypto Trading Terminal | React.js + Typescript + Redux Toolkit + Redux Saga + Tailwind CSS + Vite +Node.js

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages