A professional-grade TypeScript Smart Order Router that intelligently routes Bitcoin orders across multiple exchanges to achieve optimal execution with real-time market data from CoinGecko.
- Bitcoin Smart Routing: Routes Bitcoin orders across 2 top exchanges (Binance, Coinbase)
- Intelligent Algorithms: BestPrice, TWAP, VWAP, Liquidity-based routing
- Real-time Optimization: Continuously finds the best execution venues
- CoinGecko Integration: Real-time cryptocurrency prices and market data
- Bitcoin Trading: BTC/USD with real exchange data
- Price Charts: Interactive line graphs with multiple timeframes (price data only)
- Crypto Logos: Beautiful UI with official cryptocurrency logos
- Demo Trading: Risk-free simulation with $100,000 virtual balance
- Order Management: Complete order lifecycle tracking
- Portfolio Analytics: Real-time P&L and performance metrics
- WebSocket Integration: Real-time updates and notifications
- Next.js Frontend: Modern React-based trading interface
- Responsive Design: Works on desktop and mobile
- Dark/Light Theme: Beautiful UI with theme switching
- Real-time Charts: Interactive price charts with lightweight-charts
src/
βββ core/ # Business logic
β βββ routing/ # SOR algorithms
β βββ trading/ # Trading engine
β βββ orders/ # Order management
βββ adapters/ # External integrations
β βββ coingecko/ # CoinGecko API
βββ infrastructure/ # Technical concerns
β βββ api/ # WebSocket & REST API
β βββ config/ # Configuration
βββ shared/ # Common utilities
frontend/
βββ app/ # Next.js app router
βββ components/ # React components
β βββ trading/ # Trading interface
β βββ ui/ # Base components
β βββ layout/ # Layout components
βββ services/ # API services
βββ store/ # State management
- Node.js v20+
- npm or yarn
# Clone the repository
git clone <repository-url>
cd smart-order-router
# Install dependencies
npm install
# Install frontend dependencies
cd frontend && npm install && cd ..# Start API server with WebSocket
npm run api# Start Next.js development server
cd frontend
npm run dev# Run demo trading scenarios
npm run demo- Frontend: http://localhost:3000
- Backend API: http://localhost:8080
- WebSocket: ws://localhost:8080
The application includes a comprehensive demo mode:
- Virtual Balance: Start with $100,000
- Real Market Data: Live prices from CoinGecko
- Bitcoin Focus: 2 top exchange venues for BTC/USD
- Order Execution: Simulated trading with real market conditions
- Analytics: Track performance and P&L
npm run demoCreate .env.local in the root directory:
# CoinGecko API (optional - works without key for free tier)
COINGECKO_API_KEY=your_api_key_here
# Server Configuration
PORT=8080
NODE_ENV=developmentEdit src/configs/appConfig.ts:
export const TRADING_CONFIG = {
supportedSymbols: ['BTC/USD', 'ETH/USD', 'ADA/USD', 'DOT/USD', 'LINK/USD'],
defaultCurrency: 'usd',
};# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test suite
npm test -- --testNamePattern="routing"// Subscribe to market data
{ type: "SUBSCRIBE_MARKET_DATA" }
// Place order
{
type: "PLACE_ORDER",
payload: { symbol: "BTC/USD", side: "BUY", quantity: 0.001 }
}
// Get price series
{
type: "GET_PRICE_SERIES",
payload: { symbol: "BTC/USD", timeframe: "1d" }
}
// Get crypto metadata
{
type: "GET_COIN_METADATA",
payload: { symbols: ["BTC/USD", "ETH/USD"] }
}// Market data update
{
type: "MARKET_DATA_UPDATE",
payload: { symbol: "BTC/USD", data: [...] }
}
// Order result
{
type: "ORDER_RESULT",
payload: { status: "FILLED", symbol: "BTC/USD", ... }
}
// Price series
{
type: "PRICE_SERIES",
payload: { symbol: "BTC/USD", timeframe: "1d", points: [...] }
}- Rate Limiting: Respects CoinGecko's 100 req/min free tier
- Real-time Updates: WebSocket-based live data
- Efficient Routing: Optimized algorithms for best execution
- Scalable Architecture: Modular design for easy extension
- Demo Mode Only: No real money trading
- Input Validation: Comprehensive data validation
- Error Handling: Graceful error recovery
- Rate Limiting: Protection against API abuse
# Build and run with Docker
docker build -t smart-order-router .
docker run -p 8080:8080 -p 3000:3000 smart-order-router# Production environment
NODE_ENV=production
PORT=8080
COINGECKO_API_KEY=your_production_key- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Write comprehensive tests
- Update documentation
- Use conventional commit messages
- Ensure code passes linting
This project is licensed under the MIT License - see the LICENSE file for details.
- CoinGecko for providing excellent cryptocurrency market data API
- Next.js for the amazing React framework
- Lightweight Charts for beautiful, performant charts
- Zustand for simple state management
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki