FEDEV-3973: WebSocket price and candle streaming to the trading UI#2613
FEDEV-3973: WebSocket price and candle streaming to the trading UI#2613divhead wants to merge 1 commit into
Conversation
Phase 2 (FEDEV-3973): stream prices and live candles into the UI and SDK, behind off-by-default flags with the existing REST/poll as fallback. - sdk: WsStreamClient transport (isomorphic-ws, reconnect+backoff, snapshot- then-stream); v2 watchTokenPrices / watchCandles raw Subscriptions and a fetchTokenPrices REST snapshot, all serving normalized TokenPricesData over one shared connection - prices: useTokenRecentPricesRequest overlays the WS set behind the abWebsocket flag, throttled, with an originTs staleness fallback to the REST poll; useWsPriceOverlay emits freshness metrics - candles: DataFeed streams the forming bar into TradingView behind wsCandles; the poll stays the backstop and a monotonic onTick guard prevents rollover rewrites - fix weekly/monthly CHART_PERIODS NaN and guard empty stream frames; unit + e2e tests
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1ca4a55. Configure here.
| pricesData: data?.pricesData, | ||
| updatedAt: data?.updatedAt, | ||
| pricesData: wsFresh ? wsPrices : data?.pricesData, | ||
| updatedAt: wsFresh ? wsOriginTs : data?.updatedAt, |
There was a problem hiding this comment.
Native token missing WS prices
Medium Severity
When the WebSocket overlay is active, pricesData is taken straight from the stream snapshot. The REST fetcher still mirrors wrapped-token prices onto NATIVE_TOKEN_ADDRESS, but that step never runs on the WS path, so native-token rows can lose prices while the flag is on.
Reviewed by Cursor Bugbot for commit 1ca4a55. Configure here.
| reconnectMaxMs: this.reconnectMaxMs, | ||
| }); | ||
| } | ||
| return this._streamClient; |
There was a problem hiding this comment.
Stream URL ignores API failover
Medium Severity
getStreamClient builds the WebSocket URL once from this.ctx.api.url or streamUrlOverride and caches _streamClient. With HttpClientWithFallback, HTTP can rotate primaries after failures while the stream stays on the first host, so REST and live prices can diverge after failover.
Reviewed by Cursor Bugbot for commit 1ca4a55. Configure here.
|
|
||
| const marketsInfo = useMarketsInfoRequest(chainId, { tokensData: tokensDataResult.tokensData }); | ||
|
|
||
| useWsPriceOverlay(chainId); |
There was a problem hiding this comment.
Please check that useWsPriceOverlay does not cause rerender storm
| pricesData: wsFresh ? wsPrices : data?.pricesData, | ||
| updatedAt: wsFresh ? wsOriginTs : data?.updatedAt, |
There was a problem hiding this comment.
Could we merge prices in case API misses some?
| "apiMarkets", | ||
| "apiPositions", | ||
| "apiOrders", | ||
| "wsPrices", |
There was a problem hiding this comment.
should not we add wsCandles as well?
| updatedAt: data?.updatedAt, | ||
| pricesData: wsFresh ? wsPrices : data?.pricesData, | ||
| updatedAt: wsFresh ? wsOriginTs : data?.updatedAt, | ||
| error, |
There was a problem hiding this comment.
Error should also be selected based on ws/http data
| emitMetricTiming<WsPriceInterArrivalTiming>({ | ||
| event: "wsPrices.interArrival", | ||
| time: now - lastFrameAtRef.current, | ||
| data: { chainId }, | ||
| }); |
There was a problem hiding this comment.
should we also subsample these metrics?


Phase 2 (FEDEV-3973): stream prices and live candles into the UI and SDK, behind off-by-default flags with the existing REST/poll as fallback.