1.4 KiB
1.4 KiB
BTC/USDT Trading Demo Page
Trang demo hiển thị dữ liệu real-time từ market-data-service (Coinbase WebSocket) để phục vụ showcase trading.
Đường dẫn
/[locale]/dashboard/trading-demo
Cấu hình
# client/.env.local
NEXT_PUBLIC_MARKET_DATA_SERVICE_URL=http://localhost:7015
NEXT_PUBLIC_MARKET_DATA_WS_URL=ws://localhost:7015/ws/market
Service cần chạy ở services/market-data-service (port 7015). Nếu deploy qua API Gateway, cập nhật biến môi trường tương ứng (bao gồm cả WS).
Thành phần chính
useTradingDemohook: fetch snapshot (/api/v1/market-data/:symbol/latest) + lịch sử TradingView (/api/v1/tv/history), đồng thời subscribe WebSocket (useMarketSocket) để nhận realtime snapshot.TradingStatsCards: hiển thị price, bid/ask, volume, last trade.TradingHistoryChart: sử dụng TradingViewlightweight-chartsđể vẽ chart và cập nhật realtime theo WS.OrderSimulator: form mô phỏng buy/sell BTC dựa trên giá mới nhất (chưa khớp lệnh thật).
Quy trình chạy local
- Khởi động market-data-service (
npm run devtạiservices/market-data-service), tạo pairBTC_USDTnếu chưa có. - Ở thư mục
client/, chạynpm install(đảm bảo đã càilightweight-charts) rồinpm run dev. - Truy cập
http://localhost:3001/vi/dashboard/trading-demo(hoặc/en/...) sau khi đăng nhập.