An open API service indexing awesome lists of open source software.

https://github.com/taypyc/crypto-live-trades


https://github.com/taypyc/crypto-live-trades

eslint lucide-react postcss react react-dom tailwindcss typescript typescript-eslint vercel-deployment vitejs-react websockets

Last synced: 22 days ago
JSON representation

Awesome Lists containing this project

README

          

# ๐Ÿš€ Crypto Live Trades WebSocket

A real-time cryptocurrency trading dashboard that displays live trade data from Binance using WebSocket connections. Built with React, TypeScript, and Tailwind CSS.

## โœจ Features

- **Real-time Data**: Live cryptocurrency trade updates via Binance WebSocket API
- **Multiple Pairs**: Track 8 popular trading pairs simultaneously:
- BTC/USDT, ETH/USDT, BNB/USDT, XRP/USDT
- ADA/USDT, DOGE/USDT, MATIC/USDT, SOL/USDT
- **Multi-Currency Support**: View prices in USD, EUR, GBP, JPY, AUD, CAD, CHF, CNY
- **Responsive Design**: Beautiful, modern UI that works on all devices
- **Animated Background**: Dynamic visual effects for enhanced user experience
- **Auto-Reconnection**: Robust WebSocket connection with automatic reconnection
- **Type-Safe**: Full TypeScript implementation for better development experience

## ๐Ÿ› ๏ธ Tech Stack

- **Frontend**: React 18 with TypeScript
- **Styling**: Tailwind CSS
- **Icons**: Lucide React
- **Build Tool**: Vite
- **Linting**: ESLint with TypeScript support
- **WebSocket**: Native WebSocket API with Binance streams

## ๐Ÿš€ Getting Started

### Prerequisites

- Node.js (version 16 or higher)
- npm or yarn package manager

### Installation

1. **Clone the repository**
```bash
git clone
cd crypto-live-trades-websocket
```

2. **Install dependencies**
```bash
npm install
```

3. **Start the development server**
```bash
npm run dev
```

4. **Open your browser**
Navigate to `http://localhost:5173` to view the application

### Available Scripts

- `npm run dev` - Start the development server
- `npm run build` - Build the project for production
- `npm run preview` - Preview the production build locally
- `npm run lint` - Run ESLint for code quality checks

## ๐Ÿ“ Project Structure

```
src/
โ”œโ”€โ”€ components/ # React components
โ”‚ โ”œโ”€โ”€ AnimatedBackground.tsx
โ”‚ โ”œโ”€โ”€ CurrencySelector.tsx
โ”‚ โ”œโ”€โ”€ Footer.tsx
โ”‚ โ”œโ”€โ”€ TradeCard.tsx
โ”‚ โ””โ”€โ”€ TradeGrid.tsx
โ”œโ”€โ”€ config/ # Configuration files
โ”‚ โ”œโ”€โ”€ currencies.ts # Supported currencies
โ”‚ โ””โ”€โ”€ pairs.ts # Trading pairs
โ”œโ”€โ”€ hooks/ # Custom React hooks
โ”‚ โ”œโ”€โ”€ useBinanceWebSocket.ts
โ”‚ โ”œโ”€โ”€ useCurrency.ts
โ”‚ โ””โ”€โ”€ useMultiWebSocket.ts
โ”œโ”€โ”€ types/ # TypeScript type definitions
โ”‚ โ””โ”€โ”€ trade.ts
โ”œโ”€โ”€ utils/ # Utility functions
โ”‚ โ””โ”€โ”€ formatters.ts
โ”œโ”€โ”€ App.tsx # Main application component
โ””โ”€โ”€ main.tsx # Application entry point
```

## ๐Ÿ”Œ WebSocket Integration

The application connects to Binance's WebSocket API using the combined streams endpoint:
- **Endpoint**: `wss://stream.binance.com:9443/ws`
- **Streams**: Individual trade streams for each supported pair
- **Format**: `{symbol}@trade` (e.g., `btcusdt@trade`)

### WebSocket Features

- **Multi-stream Subscription**: Subscribe to multiple trading pairs with a single connection
- **Automatic Reconnection**: Handles connection drops with exponential backoff
- **Error Handling**: Comprehensive error handling and logging
- **Clean Disconnection**: Proper unsubscription and cleanup on component unmount

## ๐ŸŽจ UI Components

### TradeGrid
Displays all trading pairs in a responsive grid layout with real-time updates.

### TradeCard
Individual card component showing:
- Trading pair symbol
- Current price
- Buy/sell indicator
- Trade quantity
- Timestamp

### CurrencySelector
Dropdown component for switching between different fiat currencies.

### AnimatedBackground
Dynamic background with floating elements for visual appeal.

## ๐ŸŒ Multi-Currency Support

The application supports price display in multiple currencies:
- USD (US Dollar) - Default
- EUR (Euro)
- GBP (British Pound)
- JPY (Japanese Yen)
- AUD (Australian Dollar)
- CAD (Canadian Dollar)
- CHF (Swiss Franc)
- CNY (Chinese Yuan)

*Note: Currency conversion rates are fetched from external APIs and may have slight delays.*

## ๐Ÿ”ง Configuration

### Adding New Trading Pairs

To add new trading pairs, edit `src/config/pairs.ts`:

```typescript
export const tradingPairs = [
'btcusdt',
'ethusdt',
// Add new pairs here
'newpairusdt',
] as const;
```

### Adding New Currencies

To add new currencies, edit `src/config/currencies.ts`:

```typescript
export const currencies = [
{ code: 'USD', symbol: '$', name: 'US Dollar' },
// Add new currencies here
{ code: 'NEW', symbol: 'ยค', name: 'New Currency' },
] as const;
```

## ๐Ÿ“ฑ Responsive Design

The application is fully responsive and optimized for:
- **Desktop**: Full grid layout with all features
- **Tablet**: Adapted grid with touch-friendly interactions
- **Mobile**: Stacked layout optimized for small screens

## ๐Ÿšฆ Performance

- **Efficient Updates**: Only re-renders components when trade data changes
- **Memory Management**: Proper cleanup of WebSocket connections
- **Optimized Rendering**: Uses React's built-in optimization techniques
- **Lazy Loading**: Components are loaded as needed

## ๐Ÿค Contributing

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

## ๐Ÿ“„ License

This project is open source and available under the [MIT License](LICENSE).

## โš ๏ธ Disclaimer

This application is for educational and informational purposes only. It displays real-time cryptocurrency data but should not be used as the sole basis for trading decisions. Always conduct your own research and consider consulting with financial advisors before making investment decisions.

## ๐Ÿ™ Acknowledgments

- [Binance API](https://binance-docs.github.io/apidocs/) for providing real-time data
- [React](https://reactjs.org/) for the amazing framework
- [Tailwind CSS](https://tailwindcss.com/) for the utility-first CSS framework
- [Lucide React](https://lucide.dev/) for the beautiful icons