chore: add ohlcv websocket streaming#29739
Draft
sahar-fehri wants to merge 2 commits intomainfrom
Draft
Conversation
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚧
Description
Wires
OHLCVServicefrom@metamask/core-backendinto the Engine and creates auseOHLCVRealtimehook that streams live candlestick updates to the advanced chart via the existingrealtimeBarprop onAdvancedChart.Why: The advanced chart currently only renders historical data fetched via the REST OHLCV API. Users see stale candles until they navigate away and back. Real-time streaming via WebSocket keeps the chart live with 5-second heartbeat updates.
How: Follows the exact same Engine wiring pattern as
AccountActivityService— messenger, init function, Engine registration. The newuseOHLCVRealtimehook subscribes toOHLCVService:barUpdatedevents, filters by channel, and converts the WS bar format (timestamp in Unix seconds) to the chart's expected format (time in milliseconds).Local Testing Guide
Where to see logs
The WebSocket connection is managed by
BackendWebSocketServicein the RN JS Engine layer — not in a WebView. Chrome DevTools' Network > WS tab will be empty because it only captures WebView-originated connections.Instead, look for logs in:
npx react-native start)All logs are prefixed with
[OHLCVRealtime].What the logs mean
Skipping — enabled=falseSetting up subscription for channel: ...Debounce fired — calling OHLCVService:subscribeSubscribe SUCCESSBar received — channel=..., close=..., ts=...tsis candle open time in secondsCleanup — wasSubscribed=true/falseCalling OHLCVService:unsubscribewasSubscribed=true)Unsubscribe SUCCESSSubscription error on ...What to look for
Happy path: Navigate to Token Details > see
Subscribe SUCCESS> see repeatedBar receivedlogs every ~5s > navigate back > seeUnsubscribe SUCCESSDebounce working: Navigate quickly in and out of Token Details. You should see
Setting upfollowed immediately byCleanup — wasSubscribed=false(no actual WS call was made). This confirms the 300ms debounce absorbed the rapid navigation.Timestamp behavior: The
tsvalue stays the same within a candle bucket (e.g. 15 minutes for the 1D view). It only changes when the next candle opens. Identical bars with the sametsandcloseare normal — it means no trades occurred since the last heartbeat.Time range switch: Change from 1D to 1H — you should see
Unsubscribe SUCCESSfor the 15m channel followed bySubscribe SUCCESSfor a 1m channel.No leaks: Every
Subscribe SUCCESSshould eventually have a matchingUnsubscribe SUCCESS. If you see subscribes without unsubscribes, there's a leak.Where the current debug logs live
All
[OHLCVRealtime]logs are in a single file:The logs are placed at these points in the hook's
useEffect. To re-add them after removal, placeconsole.logcalls at these locations:Changelog
CHANGELOG entry:
Related issues
Fixes:
Related: MetaMask/core#8695
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist