Live Streaming
This guide covers building a real-time crypto price chart with WebSocket streaming, live mode, and short-form market overlays.Basic Live Chart
Connect a WebSocket feed to a line series with live mode enabled:How Live Mode Works
WhensetLive(true) is called:
-
Phantom point — a virtual leading data point is appended at
Date.now()that smoothly lerps toward the latest real value. This creates fluid animation even if ticks arrive only once per second. - Pulsing dot — a glowing dot marks the current price at the phantom point, pulsing with a subtle sine-wave animation.
-
Auto-scroll —
goLive()on the time scale keeps the visible range pinned to the latest data. If the user pans away, the chart returns to live after 4 seconds of inactivity. - Continuous redraw — the animation frame loop redraws the data layer every frame (for lerp + pulse), but background and overlay layers only redraw when dirty.
Price-to-Beat Overlay
Overlay a horizontal dashed line showing the opening price for a short-form market window:What Happens at Window Boundaries
When a short-form window expires (e.g., the 15-minute window closes):startRotationwaits a buffer period (default 3 seconds)- Discovers the next window’s market via the gamma proxy
- Fetches the new price-to-beat from the crypto-price endpoint
- Calls your
onRotationcallback with the new market - Resumes polling odds every
pollMsfor the new window
Multiple Coins
Run independent charts for multiple coins, each with their own series and short-form rotation:Orderbook + Chart Side-by-Side
Combine a candle chart with a live orderbook:Reconnection
Both the WebSocket feed and the OB provider handle reconnection automatically with exponential backoff (1s up to 30s). No special handling is needed in your code. For theShortFormProvider, discovery retries 3 times with a 2-second delay between attempts before giving up on a window. The rotation timer then retries at the next buffer interval.
