A Next.js application that displays real-time orderbook data from multiple cryptocurrency exchanges (OKX, Bybit, Deribit) with order simulation capabilities.
- Real-time Orderbook Display: Live data from OKX, Bybit, and Deribit
- Order Simulation: Simulate orders and see their market impact
- Market Depth Charts: Visual representation of orderbook depth
- Multi-Exchange Support: Switch between exchanges seamlessly
- Responsive Design: Works on desktop and mobile
- WebSocket Connections: Real-time updates with fallback to REST APIs
- Order Impact Analysis: Calculate slippage, market impact, and fill estimates
# Create Next.js project
npx create-next-app@latest orderbook-viewer --typescript --tailwind --eslint --app
cd orderbook-viewer
# Install dependencies
npm install zustand recharts react-hook-form zod @hookform/resolvers lucide-react clsx class-variance-authority
Create the following folder structure:
src/
├── app/
│ ├── globals.css
│ ├── layout.tsx
│ ├── page.tsx
│ └── api/orderbook/route.ts
├── components/
│ ├── ui/
│ ├── orderbook/
│ ├── forms/
│ └── layout/
├── lib/
├── store/
└── types/
Copy all the provided code files into their respective locations according to the file structure above.
npm run dev
Visit http://localhost:3000
to see the application.
The application connects to the following WebSocket endpoints:
- OKX:
wss://ws.okx.com:8443/ws/v5/public
- Bybit:
wss://stream.bybit.com/v5/public/linear
- Deribit:
wss://www.deribit.com/ws/api/v2
Popular trading pairs are supported:
- BTC-USDT, ETH-USDT (OKX, Bybit)
- BTC-USD, ETH-USD (Deribit)
- SOL-USDT, DOGE-USDT
- Choose from OKX, Bybit, or Deribit
- Enter a trading pair (e.g., BTC-USDT)
- Connection status is shown with indicators
- See live bid/ask levels with quantities
- Color-coded price levels (green for bids, red for asks)
- Spread and mid-price information
- Fill out the order form with:
- Exchange and symbol
- Buy/Sell side
- Market/Limit order type
- Price and quantity
- Timing delay
- View order impact analysis:
- Estimated fill percentage
- Average fill price
- Slippage calculation
- Market impact assessment
- Visual depth chart showing cumulative liquidity
- Bid/ask volume distribution
- Market structure visualization
- Displays real-time orderbook data
- Shows 15 levels of bids and asks
- Highlights simulated order positions
- Responsive design with proper formatting
- Order simulation form with validation
- Real-time impact calculations
- Market/limit order support
- Warning system for high-impact orders
- Interactive depth visualization
- Cumulative volume display
- Real-time updates
- Handles multiple exchange connections
- Auto-reconnection logic
- Message parsing and normalization
- Error handling and fallbacks
The application calculates several metrics for order simulation:
- Fill Percentage: How much of the order can be filled
- Average Fill Price: Weighted average execution price
- Slippage: Price deviation from best available price
- Market Impact: Percentage of orderbook depth consumed
- Total Cost: Complete order execution cost
- Zustand for global state management
- Real-time orderbook updates
- Simulated order tracking
- Exchange-specific message parsing
- Connection status tracking
- Automatic reconnection
- Graceful degradation to REST APIs
- Efficient re-rendering with React.memo
- Debounced update calculations
- Optimized chart rendering
- Memory-efficient WebSocket management
- Connection failure recovery
- API rate limiting handling
- Invalid symbol/exchange handling
- Network interruption management
- User-friendly error messages
- Historical orderbook data
- Advanced order types (Stop, OCO)
- Portfolio simulation
- Trade execution APIs
- Mobile app version
- Advanced charting tools
- This is a simulation tool for educational purposes
- No real orders are placed
- WebSocket connections are free tier (rate limited)
- All calculations are estimates based on current market data
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - see LICENSE file for details