Skip to main content
COSMICBYTEZLABS
NewsSecurityHOWTOsToolsStudyTraining
ProjectsNewsletterHire MeAbout
Subscribe

Press Enter to search or Esc to close

News
Security
HOWTOs
Tools
Study
Training
Projects
Newsletter
Hire Me
About
RSS Feed
Reading List
Subscribe

Stay in the Loop

Get the latest security alerts, tutorials, and tech insights delivered to your inbox.

Subscribe NowFree forever. No spam.
COSMICBYTEZLABS

Your trusted source for IT intelligence, cybersecurity insights, and hands-on technical guides.

1184+ Articles
136+ Guides

CONTENT

  • Latest News
  • Security Alerts
  • HOWTOs
  • Checklists
  • Projects
  • Exam Prep

RESOURCES

  • Search
  • Browse Tags
  • Newsletter Archive
  • Reading List
  • RSS Feed

COMPANY

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CosmicBytez Labs. All rights reserved.

System Status: Operational
  1. Home
  2. Projects
  3. A Real-Time Trading Dashboard with Next.js 15 and lightweight-charts
A Real-Time Trading Dashboard with Next.js 15 and lightweight-charts
PROJECTIntermediate

A Real-Time Trading Dashboard with Next.js 15 and lightweight-charts

Frontend for an algorithmic trading bot — TradingView-style candlestick charts, WebSocket auto-reconnect, dark theme, and zero SSR because the bot's API lives on a separate server.

Dylan H.

Projects

May 5, 2026
3 min read
3-5 hours

Tools & Technologies

Next.js 15lightweight-chartsWebSocketsDocker

Overview

The trading bot is fine in the terminal — but you want a chart. This is the Next.js 15 frontend that pairs with the trading bot, rendering live quotes, positions, and strategy state with TradingView's lightweight-charts library and a WebSocket connection that survives flaky networks via auto-reconnect.

Stack

  • Framework: Next.js 15.5, React 19, TypeScript
  • Styling: Tailwind CSS v4 (CSS-based config in src/app/globals.css via @theme, not tailwind.config.ts)
  • Charts: lightweight-charts (TradingView)
  • Icons: lucide-react
  • Build: output: "standalone" for Docker
  • Deployment: Docker behind Traefik + Authentik forward auth

Key Features

  • Real-time market data dashboard
  • TradingView-style candlestick charts
  • WebSocket connection with auto-reconnect for live updates
  • Dark theme — bg-gray-950 with green for profit, red for loss
  • Portfolio and position tracking
  • Strategy monitoring panels
  • Connection-status indicator in the sidebar

Architecture

  • src/lib/api.ts — fetch-based REST client. All functions return typed responses. Base URL from NEXT_PUBLIC_API_URL.
  • src/lib/WebSocketProvider.tsx — React context exposing a single shared WebSocket connection with auto-reconnect. Consumed via the useWebSocket() hook.
  • All pages are client components ("use client") using useEffect / useState. Most poll on 10–15s intervals as a fallback alongside WebSocket pushes.
  • No SSR data: the bot API is a separate server, so all data is fetched client-side. This is intentional — it keeps the platform fully decoupled from the bot.

Key Files

FilePurpose
src/lib/types.tsTypeScript types matching the Python bot's models
src/lib/api.tsFetch-based API client (NEXT_PUBLIC_API_URL)
src/lib/websocket.tsuseWebSocket hook with auto-reconnect
src/lib/WebSocketProvider.tsxReact context for shared WebSocket
src/lib/utils.tsFormatting and color utilities

Environment Variables

VariablePurpose
NEXT_PUBLIC_API_URLBot API base URL (e.g. http://bot:8080/api/v1)
NEXT_PUBLIC_WS_URLWebSocket URL (e.g. ws://bot:8080/api/v1/ws)

Both are intentionally NEXT_PUBLIC_* — the bot API runs on the same internal network and the values are not secrets.

Docker Build

docker build \
  --build-arg NEXT_PUBLIC_API_URL=http://bot:8080/api/v1 \
  --build-arg NEXT_PUBLIC_WS_URL=ws://bot:8080/api/v1/ws \
  -t azu-trading-platform .

In production the platform sits behind Authentik forward auth (Traefik middleware). The bot API has no Authentik in front of it because Authentik's CSRF preflight breaks WebSocket upgrades — it relies on network-level controls instead.

Lessons Learned

  • This project lives on master, not main. Don't fight your existing branch convention for the sake of consistency unless you're rewriting history.
  • Tailwind v4 puts theme tokens in CSS, not in a JS config — @theme blocks in globals.css replace tailwind.config.ts. Worth knowing before you go looking for the file.
  • Move WebSocket auth out of the URL: passing tokens in the connection URL leaks them into proxy access logs. Authenticate in the first message instead.
#Next.js#React#WebSocket#lightweight-charts#Trading#TypeScript#Tailwind

Related Articles

How CosmicBytez Labs Is Built: Next.js 16, velite, and Resend

A meta writeup about this site — content pipeline via velite (the contentlayer2 successor), a Resend-backed newsletter wired through a Vercel cron, the IT exam prep with 770 practice questions across 11 cert tracks, and the 8-tool utility suite.

3 min read

Orbit: An Offline-First Fitness PWA with Dual Storage Backend

A household fitness PWA with weight tracking, meal planning, workouts, and pantry — built on Next.js 15 with a single codebase that runs against either Supabase or local SQLite, plus an IndexedDB mutation queue for offline.

3 min read

Self-Hosted IPTV Manager with HDHomeRun Emulation for Plex

An IPTV stream manager that pretends to be an HDHomeRun tuner so Plex DVR can record over-the-air-style live TV — M3U import, tier-based channel classification, FFmpeg HLS remux, and an XMLTV EPG.

3 min read
Back to all Projects